package com.zoweunion.mechanic.util.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.dao.PromotionCouponDao;
import com.zoweunion.mechanic.dao.TSSsVehicleModelDao;
import com.zoweunion.mechanic.dao.UserCouponDao;
import com.zoweunion.mechanic.dao.app.AppDao;
import com.zoweunion.mechanic.dao.app.ToolCarDataMapper;
import com.zoweunion.mechanic.dao.base.LockCarMapper;
import com.zoweunion.mechanic.dao.base.MessageRecordDao;
import com.zoweunion.mechanic.dao.base.UserDao;
import com.zoweunion.mechanic.plugins.redis.RedisUtil;
import com.zoweunion.mechanic.service.app.impl.AppServiceImpl;
import com.zoweunion.mechanic.service.app.impl.ToolCarDataServiceImpl;
import com.zoweunion.mechanic.service.base.BaseService;
import com.zoweunion.mechanic.service.base.UpkeepService;
import com.zoweunion.mechanic.service.impl.FacilitatorPersonnelRelationServiceImpl;
import com.zoweunion.mechanic.util.*;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.gaode.AddressGEOUtil;
import jodd.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 消息队列的数据
 *
 * @author rentianfeng
 */
@Component
public class MQDataAlarmPush extends BaseController {

    @Autowired
    private ToolCarDataMapper toolCarDataMapper;
    @Autowired
    private CarDataAbnormalTask carDataAbnormalTask;
    @Autowired
    private ToolCarDataServiceImpl toolCarDataServiceImpl;
    @Autowired
    private BaseService baseService;
    @Autowired
    private MessageRecordDao messageRecordDao;
    @Autowired
    private JiGuangPushUtil jiGuangPushUtil;
    @Autowired
    private PromotionCouponDao promotionCouponDao;
    @Autowired
    private UserCouponDao userCouponDao;
    @Autowired
    private Environment env;
    @Autowired
    private FacilitatorPersonnelRelationServiceImpl relationService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private AppDao appDao;
    @Autowired
    private AppServiceImpl appServiceImpl;
    @Autowired
    private TSSsVehicleModelDao tSSsVehicleModelDao;
    @Autowired
    private UpkeepService upkeepService;
    @Autowired
    private ToolCarDataServiceImpl toolCarDataService;
    @Autowired
    private UserDao userDao;
    @Autowired
    private LockCarMapper lockCarMapper;

    public static final String postFC = "https://internal.cel-cat.com.cn/xcadmin/public/index.php/api/postFC";
    public static final String Authorization = "Authorization";
    public static final String envThingsId = "envThingsId";

    @Resource(name = "cachedThreadPool")
    private ExecutorService executorService;

    // 消息队列，用来处理保养，故障等提醒
    public void channelRealRemindAlarm(String message) throws Exception {
        // System.out.println(message);
//         {"sample_time":"2021-01-26 17:33:31","things_id":"18201110892",
//         "FMI1":"0","CSQ":"22","validRotateSpeed":"0.000","lockStatus":"0",
//         "IntakeTemperature":"-40","Ignition":"0.0","GPSlatitude":"29.79922",
//         "Location_mode":"15","DSZSC":"0.00","FDJSSYH":"0.00","RotateSpeed":"0.000",
//         "FDJNJ":"-125","LS3":"0","FuelGauge":"0","RYZSFZB":"0","BTRYZYQYL":"0",
//         "OC3":"0","FuelemTperature":"-40","RYYL":"0","FDJZJBFB":"0","LS1":"0",
//         "DSZYYXHL":"0.0","FDJZZS":"0","WaterTemperature":"-40","OC1":"0",
//         "SPN3":"0","EngineTotalHours":"0.00","KQJQYL":"0","YYB1CKYY":"0",
//         "BTYYYWD":"0","TotalFuelAmount":"0.0","BatVol":"25.8","YYB2CKYY":"0",
//         "SPN2":"0","OperatingHours":"0.00","LS2":"0","FMI3":"0",
//         "GPSlongitude":"106.09805","1939_001":"1","MCU_temperature":"44.0",
//         "SPN1":"0","isCAT":1,"OC2":"0","OilPressure":"0","FMI2":"0",
//         "things_sample_time":"2021-01-26 17:33:16","GP_NUM":2,"status":2,
//         "templateId":"123","lock_status":2,"GAODElongitude":106.09805,"GAODElatitude":29.79922,"Location":true}

        // 计算时间，每天晚上22点到早上6点没有推送
        Map<String, Object> reqMap = JSONObject.parseObject(message, Map.class);
        String thingsId = Orgin.getString(reqMap, "things_id");
        Date sampleTime = Orgin.getDateTime(reqMap, "sample_time");

        if(reqMap.containsKey("head_message")) {
           this.operateHeadMessage(reqMap); // 根据《通讯协议2020.3.B.doc》协议规则，入库透传数据
        } else {
            // APP推送的报警
            if (getTime(6) < sampleTime.getTime() && sampleTime.getTime() < getTime(22)) {

                //怠速时间过长 34
                excessiveIdleTimeWarning(reqMap, thingsId);

                // 故障预警 16
                faultWarning(reqMap, thingsId);

                // 高温预警 17,18
                //waterTemperature(reqMap, thingsId);
                waterTemperature1(reqMap, thingsId);

                // 机油高温预警 30 发动机油温
                //highOilTemperatureWarning(reqMap, thingsId);
                highOilTemperatureWarning1(reqMap, thingsId);

                // 机油压力过高预警 31
                //highOilPressureWarning(reqMap, thingsId);
                highOilPressureWarning1(reqMap, thingsId);

                // 液压油温度过高/低预警 32/33
                //hydraulicOilTemperatureWarning(reqMap, thingsId);
                    //hydraulicOilTemperatureWarning1(reqMap, thingsId);


                // 保养提醒  35
                serviceReminder(reqMap, thingsId);

                // 燃油液位预警 15
               //fuelGaugeWarning(reqMap, thingsId);
            }

            // 插入每天工作的设备
            insertOnlineEveryDay(reqMap, thingsId);

            executorService.execute(() -> {
                if (reqMap.containsKey(Constants.THINGS_IsCAT)) {
                    this.pushKt(reqMap, thingsId);
                }
            });
            //推送环卫api
    //        try {
    //            pushEnvironmental(reqMap,thingsId);
    //        } catch (Exception e) {
    //            e.printStackTrace();
    //        }

            // TODO 1、高德地图猎鹰轨迹的注册
            // TODo 2、170
            // TODO 1、卡特设备
        }
    }

    //怠速报警
    //收到数据之后，对转速进行判断，小于1000插入数据库表中，并查询30分钟内插入多少条数据
    //如果大于90条，则进行推送
    private void excessiveIdleTimeWarning(Map<String, Object> reqMap, String thingsId) {
        if(reqMap.get("RotateSpeed") != null) {
            Double rotateSpeed = Orgin.getDoubleValue(reqMap, "RotateSpeed");
            if (rotateSpeed < 1000.000 && rotateSpeed > 0.000) {
                //小于1000.000就插入一条数据
                toolCarDataMapper.insertIdleTimeHigh(thingsId, rotateSpeed);
                //查询30分钟内插入数据的条数
                int dataCount = toolCarDataMapper.selectIdleTimeHigh(thingsId);
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                //推送频率为一条/20s  30分钟为90条 大于等于90条则进行推送
                if (dataCount >= 90) {
                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                    //查询20分钟内是否推送过 推送过则20分钟内不再推送
                    int pushCountWithinTwentyMinutes = toolCarDataMapper.selectPushCountWithinTwentyMinutes(user_id, thingsId, 34);
                    if (pushCountWithinTwentyMinutes == 0) {
                        //查询当天推送的次数
                        int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 34);
                        //限制当天推送次数 超过50条不再推送
                        if (count <= 5) {
                            userList.forEach(item -> {
                                if (Orgin.getString(item, "advice_name") != null) {
                                    try{
                                    carDataAbnormalTask.jPushIdleTimeHigh(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                   // carDataAbnormalTask.jPushIdleTimeHigh(item, Orgin.getString(item, "d_id"), 1, count + 1);

                           /* // 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushIdleTimeHigh(item, kfMap.get("id").toString(), 1, count + 1);
                                }
                            }*/

                                    reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                    List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                    guanliyuanList.forEach(guanliyuanItem -> {
                                        String guanliyuanUserId = guanliyuanItem.get("id");
                                        carDataAbnormalTask.jPushIdleTimeHigh(item, guanliyuanUserId, 1, count + 1);

                                    });
                                } catch (Exception e){
                                    e.printStackTrace();
                                    logger.error(e.getMessage());
                                }
                                } else {
                                    try{
                                    carDataAbnormalTask.jPushIdleTimeHigh(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                    carDataAbnormalTask.jPushIdleTimeHigh(item, Orgin.getString(item, "d_id"), 2, count + 1);

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushIdleTimeHigh(item, kfMap.get("id").toString(), 2, count + 1);
                                }
                            }*/

                                    reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                    List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                    guanliyuanList.forEach(guanliyuanItem -> {
                                        String guanliyuanUserId = guanliyuanItem.get("id");
                                        carDataAbnormalTask.jPushIdleTimeHigh(item, guanliyuanUserId, 2, count + 1);
                                    });
                                } catch (Exception e){
                                            e.printStackTrace();
                                            logger.error(e.getMessage());
                                        }
                                }
                                //插入推送
                                messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 13);
                            });
                        }
                    }
                }
            }
        }
    }

    //液压油温度过高或过低报警
    //获取温度数值，检查今日该车辆是否添加数据，没有添加则添加一条，今日再次出现则进入推送机制
    //进入推送机制，每日超过10条不进行推送
    private void hydraulicOilTemperatureWarning1(Map<String, Object> reqMap, String thingsId){
        if(reqMap.get("BTYYYWD") != null){
            int temperature=Orgin.getIntValue(reqMap,"BTYYYWD");
            //if  检查温度是否小于30  大于75
            if (temperature < 30 || temperature > 75){
                List<String> thingsList=new ArrayList<>();
                thingsList.add(thingsId);
                //if  检查温度是否在75-95之间
                if (temperature > 75 && temperature < 95){
                    Map<String, Object> map = toolCarDataMapper.selectHdlOilHighTemperature(thingsId);
                    //if  检查map是否为空
                    if (map ==null){
                        toolCarDataMapper.insertHdlOilHighTemperature(thingsId);
                    }else {
                        TimerTask timerTask = new TimerTask() {
                            @Override
                            public void run() {
                                if (temperature > 75 && temperature < 95){
                                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                                    String user_id = userList.get(0).get("o_id").toString();
                                    //查询推送的次数
                                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 32);
                                    if (count <= 5){
                                        userList.forEach(item ->{
                                            if (Orgin.getString(item, "advice_name") != null){
                                                try {
                                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "d_id"), 1, count + 1);
                                                }catch (Exception e){
                                                    e.printStackTrace();
                                                    logger.error(e.getMessage());
                                                }
                                            }else {
                                                try{
                                                carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                                carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "d_id"), 2, count + 1);
                                            } catch (Exception e){
                                                        e.printStackTrace();
                                                        logger.error(e.getMessage());
                                                    }
                                            }
                                            messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 11);
                                        });
                                    }//总数是否小于50进行推送
                                }//60s后执行的if判断
                            }//定时器run方法
                        };//定时器
                        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(2);
                        scheduledThreadPool.schedule(timerTask, 1, TimeUnit.MINUTES);
                    }
                }else if (temperature >= 95){
                    Map<String, Object> map = toolCarDataMapper.selectHdlOilHighTemperature(thingsId);
                    if (map == null){
                        toolCarDataMapper.insertHdlOilHighTemperature(thingsId);
                    }else {
                        List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                        String user_id = userList.get(0).get("o_id").toString();
                        //查询推送的次数
                        int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 32);
                        if (count <= 5){
                            userList.forEach(item ->{
                                if (Orgin.getString(item, "advice_name") != null){
                                    try{
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                   carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "d_id"), 1, count + 1);
                                } catch (Exception e){
                                    e.printStackTrace();
                                    logger.error(e.getMessage());
                                }
                                }else {
                                    try{
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "d_id"), 2, count + 1);
                                    } catch (Exception e){
                                        e.printStackTrace();
                                        logger.error(e.getMessage());
                                    }
                                }
                                messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 11);
                            });
                        }//总数是否小于50进行推送
                    }
                }else if(temperature < 30 && temperature > 0){
                    Map<String, Object> map = toolCarDataMapper.selectHdlOilLowTemperature(thingsId);
                    //if  检查map是否为空
                    if (map ==null){
                        toolCarDataMapper.insertHdlOilLowTemperature(thingsId);
                    }else {
                        TimerTask timerTask = new TimerTask() {
                            @Override
                            public void run() {
                                if (temperature < 30 && temperature > 0){
                                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                                    String user_id = userList.get(0).get("o_id").toString();
                                    //查询推送的次数
                                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 33);
                                    if (count <= 5){
                                        userList.forEach(item ->{
                                            if (Orgin.getString(item, "advice_name") != null){
                                                try{
                                                carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                                carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "d_id"), 1, count + 1);
                                                } catch (Exception e){
                                                    e.printStackTrace();
                                                    logger.error(e.getMessage());
                                                }
                                            }else {
                                                try{
                                                carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                                carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "d_id"), 2, count + 1);
                                                } catch (Exception e){
                                                    e.printStackTrace();
                                                    logger.error(e.getMessage());
                                                }
                                            }
                                            messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 12);
                                        });
                                    }//总数是否小于50进行推送
                                }//60s后执行的if判断
                            }//定时器run方法
                        };//定时器
                        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(2);
                        scheduledThreadPool.schedule(timerTask, 5, TimeUnit.MINUTES);
                    }
                }
            }//if  检查温度是否小于30  大于75
        }//if  判断报警是否为空
    }



    //液压油温度过高或过低
    private void hydraulicOilTemperatureWarning(Map<String, Object> reqMap, String thingsId) {
        if(reqMap.get("BTYYYWD") != null) {
            int hydraulicOilTemperature = Orgin.getIntValue(reqMap, "BTYYYWD");
            if (hydraulicOilTemperature < 30 || hydraulicOilTemperature > 80) {
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                if (hydraulicOilTemperature > 80) {
                    Map<String, Object> map = toolCarDataMapper.selectHdlOilHighTemperature(thingsId);
                    if (map == null) {
                        toolCarDataMapper.insertHdlOilHighTemperature(thingsId);
                    } else if (Orgin.getIntValue(map, "hdloil_high_count") % 15 == 0) {
                        List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                        String user_id = userList.get(0).get("o_id").toString();
                        //查询推送的次数
                        int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 32);
                        //限制当天推送次数 超过50条不再推送
                        if (count <= 50) {
                            userList.forEach(item -> {
                                if (Orgin.getString(item, "advice_name") != null) {
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "d_id"), 1, count + 1);

                                /*// 如果area为空，根据经纬度解析出区域编码
                                if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                    reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                                }
                                //获取客服列表
                                List<Map<String, Object>> kfList = null;
                                reqMap.put("s_id", item .get("s_id"));
                                if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                    kfList = appDao.findUserByRAreaCode(reqMap);
                                    if (null == kfList || kfList.size() == 0) {
                                        kfList = appDao.findUserByRid(reqMap);
                                    }
                                } else {
                                    kfList = appDao.findUserByRid(reqMap);
                                }

                                // 循环推送消息给符合条件的客服
                                if (kfList.size() > 0) {
                                    for (Map<String, Object> kfMap : kfList) {
                                        carDataAbnormalTask.jPushHdlOilHighTemp(item, kfMap.get("id").toString(), 1, count + 1);
                                    }
                                }

                                reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                guanliyuanList.forEach(guanliyuanItem -> {
                                    String guanliyuanUserId = guanliyuanItem.get("id");
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, guanliyuanUserId, 1, count + 1);
                                });*/
                                } else {
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, Orgin.getString(item, "d_id"), 2, count + 1);

                               /* // 如果area为空，根据经纬度解析出区域编码
                                if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                    reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                                }
                                //获取客服列表
                                List<Map<String, Object>> kfList = null;
                                reqMap.put("s_id", item.get("s_id"));
                                if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                    kfList = appDao.findUserByRAreaCode(reqMap);
                                    if (null == kfList || kfList.size() == 0) {
                                        kfList = appDao.findUserByRid(reqMap);
                                    }
                                } else {
                                    kfList = appDao.findUserByRid(reqMap);
                                }

                                // 循环推送消息给符合条件的客服
                                if (kfList.size() > 0) {
                                    for (Map<String, Object> kfMap : kfList) {
                                        carDataAbnormalTask.jPushHdlOilHighTemp(item, kfMap.get("id").toString(), 2, count + 1);
                                    }
                                }

                                reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                guanliyuanList.forEach(guanliyuanItem -> {
                                    String guanliyuanUserId = guanliyuanItem.get("id");
                                    carDataAbnormalTask.jPushHdlOilHighTemp(item, guanliyuanUserId, 2, count + 1);
                                });*/
                                }
                                //插入推送
                                messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 11);
                                toolCarDataMapper.updateHighHdlOilPressureCount(thingsId, Orgin.getIntValue(map, "hdloil_high_count") + 1);
                            });
                        }
                    } else {
                        toolCarDataMapper.updateHighHdlOilPressureCount(thingsId, Orgin.getIntValue(map, "hdloil_high_count") + 1);
                    }
                } else {
                    Map<String, Object> map = toolCarDataMapper.selectHdlOilLowTemperature(thingsId);
                    if (map == null) {
                        toolCarDataMapper.insertHdlOilLowTemperature(thingsId);
                    } else if (Orgin.getIntValue(map, "hdloil_low_count") % 30 == 0) {
                        List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                        String user_id = userList.get(0).get("o_id").toString();
                        //查询推送的次数
                        int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 33);
                        //限制当天推送次数 超过50条不再推送
                        if (count <= 50) {
                            userList.forEach(item -> {
                                if (Orgin.getString(item, "advice_name") != null) {
                                    carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                    carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "d_id"), 1, count + 1);

                                /*// 如果area为空，根据经纬度解析出区域编码
                                if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                    reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                                }
                                //获取客服列表
                                List<Map<String, Object>> kfList = null;
                                reqMap.put("s_id", item.get("s_id"));
                                if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                    kfList = appDao.findUserByRAreaCode(reqMap);
                                    if (null == kfList || kfList.size() == 0) {
                                        kfList = appDao.findUserByRid(reqMap);
                                    }
                                } else {
                                    kfList = appDao.findUserByRid(reqMap);
                                }

                                // 循环推送消息给符合条件的客服
                                if (kfList.size() > 0) {
                                    for (Map<String, Object> kfMap : kfList) {
                                        carDataAbnormalTask.jPushHdlOilLowTemp(item, kfMap.get("id").toString(), 1, count + 1);
                                    }
                                }

                                reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                guanliyuanList.forEach(guanliyuanItem -> {
                                    String guanliyuanUserId = guanliyuanItem.get("id");
                                    carDataAbnormalTask.jPushHdlOilLowTemp(item, guanliyuanUserId, 1, count + 1);
                                });*/
                                } else {
                                    carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                    carDataAbnormalTask.jPushHdlOilLowTemp(item, Orgin.getString(item, "d_id"), 2, count + 1);

                               /* // 如果area为空，根据经纬度解析出区域编码
                                if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                    reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                                }
                                //获取客服列表
                                List<Map<String, Object>> kfList = null;
                                reqMap.put("s_id", item.get("s_id"));
                                if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                    kfList = appDao.findUserByRAreaCode(reqMap);
                                    if (null == kfList || kfList.size() == 0) {
                                        kfList = appDao.findUserByRid(reqMap);
                                    }
                                } else {
                                    kfList = appDao.findUserByRid(reqMap);
                                }

                                // 循环推送消息给符合条件的客服
                                if (kfList.size() > 0) {
                                    for (Map<String, Object> kfMap : kfList) {
                                        carDataAbnormalTask.jPushHdlOilLowTemp(item, kfMap.get("id").toString(), 2, count + 1);
                                    }
                                }

                                reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                guanliyuanList.forEach(guanliyuanItem -> {
                                    String guanliyuanUserId = guanliyuanItem.get("id");
                                    carDataAbnormalTask.jPushHdlOilLowTemp(item, guanliyuanUserId, 2, count + 1);
                                });*/
                                }
                                //插入推送
                                messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 12);
                                toolCarDataMapper.updateLowHdlOilPressureCount(thingsId, Orgin.getIntValue(map, "hdloil_low_count") + 1);
                            });
                        }
                    } else {
                        toolCarDataMapper.updateLowHdlOilPressureCount(thingsId, Orgin.getIntValue(map, "hdloil_low_count") + 1);
                    }

                }

            }
        }
    }

    //机油压力过高
    //获取机油的压力，判断该车辆今日是否第一次插入数据,如果是第一次，则插入油压表中；如果不是，则进行推送，获取该车主的信息，进行推送
    private void highOilPressureWarning1(Map<String, Object> reqMap, String thingsId) throws Exception {
        if (reqMap.get("OilPressure") != null) {
            int oilPressure = Orgin.getIntValue(reqMap, "OilPressure");
            if (oilPressure > 800) {
                Map<String, Object> map = toolCarDataMapper.selectOilPressure(thingsId);
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                if (map == null){
                    toolCarDataMapper.insertOilPressure(thingsId);
                }else {
                    List<String> listByCreateTime = toolCarDataMapper.selectNowDayCountMessages(DateUtil.formatDate(new Date()), thingsId, 31);
                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                    //查询推送的次数
                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 31);
                    if (count <= 5) {
                        if (!CollectionUtils.isEmpty(listByCreateTime)) {
                            String date = listByCreateTime.get(0);
                            //计算一下是否是否在两分钟之内
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            long min = DateUtil.dateDiff(date, sdf.format(new Date()), "yyyy-MM-dd HH:mm:ss");
                            if (min < 2) {
                                userList.forEach(item -> {
                                    if (Orgin.getString(item, "advice_name") != null) {
                                        try {
                                            carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                            // carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "d_id"), 1, count + 1);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            logger.error(e.getMessage());
                                        }
                                    } else {
                                        try {
                                            carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                            carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "d_id"), 2, count + 1);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            logger.error(e.getMessage());
                                        }
                                    }
                                    messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 10);
                                });
                                //总数是否小于50进行推送
                            }
                        } else {
                            messageRecordDao.addMessageRecord(map);
                        }
                    }
                }//两分钟后再次查询机油压力
            }//判断是否>800
        }// if1
    }



    //机油压力过高
    private void highOilPressureWarning(Map<String, Object> reqMap, String thingsId) {
        if (reqMap.get("OilPressure") != null) {
            int oilPressure = Orgin.getIntValue(reqMap, "OilPressure");
            if (oilPressure > 800) {
                Map<String, Object> map = toolCarDataMapper.selectOilPressure(thingsId);
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                if (map == null) {
                    toolCarDataMapper.insertOilPressure(thingsId);
                } else if (Orgin.getIntValue(map, "oil_pressure_count") % 6 == 0) {
                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                    //查询推送的次数
                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 31);
                    //限制当天推送次数 超过50条不再推送
                    if (count <= 50) {
                        userList.forEach(item -> {
                            if (Orgin.getString(item, "advice_name") != null) {
                                carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "d_id"), 1, count + 1);

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushOilPressure(item, kfMap.get("id").toString(), 1, count + 1);
                                }
                            }

                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                            guanliyuanList.forEach(guanliyuanItem -> {
                                String guanliyuanUserId = guanliyuanItem.get("id");
                                carDataAbnormalTask.jPushOilPressure(item, guanliyuanUserId, 1, count + 1);
                            });*/
                            } else {
                                carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                carDataAbnormalTask.jPushOilPressure(item, Orgin.getString(item, "d_id"), 2, count + 1);

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushOilPressure(item, kfMap.get("id").toString(), 2, count + 1);
                                }
                            }

                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                            guanliyuanList.forEach(guanliyuanItem -> {
                                String guanliyuanUserId = guanliyuanItem.get("id");
                                carDataAbnormalTask.jPushOilPressure(item, guanliyuanUserId, 2, count + 1);
                            });*/
                            }
                            //插入推送
                            messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 10);
                            toolCarDataMapper.updateOilPressureCount(thingsId, Orgin.getIntValue(map, "oil_pressure_count") + 1);
                        });
                    }
                } else {
                    toolCarDataMapper.updateOilPressureCount(thingsId, Orgin.getIntValue(map, "oil_pressure_count") + 1);
                }
            }
        }
    }
    //发动机油温
    //拿到数据之后判断油温大小
    //先去油温表查询今日是否添加过该车辆数据,没有数据就先插入一条
    //如果有数据，获取该车辆车主的个人信息，并查询今日推送次数，小于50次就进行推送
    private void highOilTemperatureWarning1(Map<String, Object> reqMap, String thingsId) throws Exception {
        if(reqMap.get("EngineOilTemperature") != null){
            int engineOilTemperature = Orgin.getIntValue(reqMap, "EngineOilTemperature");
            if (engineOilTemperature > 110){
                Map<String, Object> map = toolCarDataMapper.selectOilTemper(thingsId);
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                if (map == null){
                    toolCarDataMapper.insertOilTemper(thingsId);
                }else {
                    List<String> listByCreateTime = toolCarDataMapper.selectNowDayCountMessages(DateUtil.formatDate(new Date()), thingsId, 30);
                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                    //查询推送的次数
                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 30);
                    //限制当天推送次数 超过5条不再推送
                    if (count <= 5) {
                        if (!CollectionUtils.isEmpty(listByCreateTime)) {
                            String date = listByCreateTime.get(0);
                            //计算一下是否是否在两分钟之内
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            long min = DateUtil.dateDiff(date, sdf.format(new Date()), "yyyy-MM-dd HH:mm:ss");
                            if (min < 2) {
                                userList.forEach(item -> {
                                    if (Orgin.getString(item, "advice_name") != null) {
                                        try {
                                            carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                          //  carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "d_id"), 1, count + 1);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            logger.error(e.getMessage());
                                        }
                                    } else {
                                        try {
                                            carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                            carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "d_id"), 2, count + 1);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            logger.error(e.getMessage());
                                        }
                                    }
                                    //插入推送
                                    messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 9);
                                });

                            }
                        } else {
                            messageRecordDao.addMessageRecord(map);
                        }
                    }
                }
            }//判断发动机油温是否>110
        }//判断是否为空



    }

    private void highOilTemperatureWarning(Map<String, Object> reqMap, String thingsId) {
        if(reqMap.get("EngineOilTemperature") != null) {
            int engineOilTemperature = Orgin.getIntValue(reqMap, "EngineOilTemperature");
            if (engineOilTemperature > 110) {
                Map<String, Object> map = toolCarDataMapper.selectOilTemper(thingsId);
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                if (map == null) {
                    toolCarDataMapper.insertOilTemper(thingsId);
                } else if (Orgin.getIntValue(map, "oil_count") % 6 == 0) {
                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                    //查询推送的次数
                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 30);
                    //限制当天推送次数 超过50条不再推送
                    if (count <= 50) {
                        userList.forEach(item -> {
                            if (Orgin.getString(item, "advice_name") != null) {
                                carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "o_id"), 1, count + 1);
                                carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "d_id"), 1, count + 1);

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushOilTemp(item, kfMap.get("id").toString(), 1, count + 1);
                                }
                            }

                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                            guanliyuanList.forEach(guanliyuanItem -> {
                                String guanliyuanUserId = guanliyuanItem.get("id");
                                carDataAbnormalTask.jPushOilTemp(item, guanliyuanUserId, 1, count + 1);
                            });*/
                            } else {
                                carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "o_id"), 2, count + 1);
                                carDataAbnormalTask.jPushOilTemp(item, Orgin.getString(item, "d_id"), 2, count + 1);

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushOilTemp(item, kfMap.get("id").toString(), 2, count + 1);
                                }
                            }

                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                            guanliyuanList.forEach(guanliyuanItem -> {
                                String guanliyuanUserId = guanliyuanItem.get("id");
                                carDataAbnormalTask.jPushOilTemp(item, guanliyuanUserId, 2, count + 1);
                            });*/
                            }
                            //插入推送
                            messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 9);
                            toolCarDataMapper.updateOilCount(thingsId, Orgin.getIntValue(map, "oil_count") + 1);
                        });
                    }

                } else {
                    toolCarDataMapper.updateOilCount(thingsId, Orgin.getIntValue(map, "oil_count") + 1);
                }
            }
        }
    }
    //保养报警
    // 先获取车辆信息，再去获取车辆是否设置了保养套餐，如果设置了，并且达到保养时长就进行推送，每天推送一条
    private void serviceReminder(Map<String, Object> reqMap, String thingsId) {
        if (reqMap.get("EngineTotalHours") != null) {
            int engineTotalHours = Orgin.getIntValue(reqMap, "EngineTotalHours");
            Map<String, Object> map = toolCarDataMapper.selectCarInfoByThingsId(thingsId);
            List<Map<String, Object>> resultMap = upkeepService.getUpkeep_timeByCondition(map);
            List<Boolean> list = new ArrayList<>();
            if (resultMap.size() != 0) {
                for (Map<String, Object> stringObjectMap : resultMap) {
                    if (engineTotalHours % (int) stringObjectMap.get("upkeep_time") == 0) {
                        list.add(true);
                    }
                }
                if (list.size() != 0) {
                    List<String> thingsList = new ArrayList<>();
                    thingsList.add(thingsId);
                   List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                     //查询推送的次数
                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 35);
                    //限制当天推送次数，一天推送一条
                    if (count < 2) {
                        userList.forEach(item -> {
                            if (Orgin.getString(item, "advice_name") != null) {

                                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(Orgin.getString(item, "things_id"));
                                Map<String, Object> message = ownerCars.get(0);
                                item.put("car_no", message.get("car_no"));
                                item.put("longitude", reqMap.get("GAODElongitude"));
                                item.put("latitude", reqMap.get("GAODElatitude"));
                                item.put("user_id", message.get("o_id"));
                                try{
                                    reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                    List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                    guanliyuanList.forEach(guanliyuanItem -> {
                                        String guanliyuanUserId = guanliyuanItem.get("id");
                                        carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, guanliyuanUserId, 1);
                                    });
                                carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, Orgin.getString(item, "o_id"), 1);
                                carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, Orgin.getString(item, "d_id"), 1);

                                } catch (Exception e){
                                    e.printStackTrace();
                                    logger.error(e.getMessage());
                                }

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, kfMap.get("id").toString(), 1);
                                }
                            }*/


                            } else {
                                try{
                                carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, Orgin.getString(item, "o_id"), 2);
                                carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, Orgin.getString(item, "d_id"), 2);


                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, kfMap.get("id").toString(), 2);
                                }
                            }*/

                                reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                                List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                                guanliyuanList.forEach(guanliyuanItem -> {
                                    String guanliyuanUserId = guanliyuanItem.get("id");
                                    carDataAbnormalTask.jPushServiceReminder(engineTotalHours, item, guanliyuanUserId, 2);
                                });
                                } catch (Exception e){
                                    e.printStackTrace();
                                    logger.error(e.getMessage());
                                }
                            }
                            //插入推送
                            messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 14);
                        });
                    }
                }
            }
        }
    }


    public void pushEnvironmental(Map<String, Object> reqMap, String thingsId) {

        //判断redis是否包含
        if (this.isExist(thingsId)) {//判断是否环卫服务商

            Map<String, Object> sid = toolCarDataMapper.getCarInfo(thingsId);
            Map<Object, Object> map = new HashMap<>();
            Long id = getId(Orgin.getString(sid, "id"));
            String carNo = Orgin.getString(sid, "car_no");
            //carNo = "苏B-V5110";
            double gpSlatitude = Orgin.getDoubleValue(reqMap, "GPSlatitude");
            double gpslongitude = Orgin.getDoubleValue(reqMap, "GPSlongitude");
            map.put("vKey", MD5.md5(id + "|" + carNo));//加密参数
            map.put("id", id);//bd_car-id
            map.put("name", carNo);//bd_car-carNo
            map.put("gpstime", Orgin.getDateTime(reqMap, "sample_time").getTime());//盒子上传时间
            map.put("recvtime", System.currentTimeMillis());
            map.put("lat", gpSlatitude);
            map.put("lng", gpslongitude);
            map.put("lat_xz", Double.parseDouble(String.format("%.4f", Orgin.getDoubleValue(reqMap, "GAODElatitude"))));
            map.put("lng_xz", Double.parseDouble(String.format("%.4f", Orgin.getDoubleValue(reqMap, "GAODElongitude"))));
            map.put("state", "后门开启");
            map.put("speed", 0);
            map.put("direct", 0);
            map.put("temp", 1);
            map.put("oil", Math.ceil((Orgin.getDoubleValue(reqMap, "WaterLevel") / 1.5) * 9870));//剩余水量
            //map.put("oil",Math.ceil(0.6/1.5)*9870);//剩余水量
            map.put("oilMN1", 3);
            map.put("oilMN2", 4);
            map.put("distance", getDistance(thingsId));
            map.put("totalDis", 18616);
            map.put("av", 1);
            map.put("info", gpSlatitude + "," + gpslongitude);
            map.put("vhcofflinemin", 10);
            map.put("stopDefDis", 0);
            map.put("stopDefLat", 0);
            map.put("stopDefLng", 0);
            map.put("temp1", 5);
            map.put("temp2", 6);
            map.put("temp3", 7);
            map.put("temp4", 8);

            if (gpSlatitude == 0) {

                return;
            }

            //todo 推送完清除
            HttpRequest sendData =
                    HttpRequest.post(Constants.ENVIRONMENTAL).bodyText(JSONObject.toJSONString(map))
                            .contentType("application/json")
                            .charset("utf-8");

            String mapRouteString = sendData.send().bodyText();

            System.out.println(mapRouteString);
        }
    }

    public Long getId(String UUID) {
        Integer userId = UUID.toString().hashCode();
        // String.hashCode()可能会是负数，如果为负数需要转换为正数
        userId = userId < 0 ? -userId : userId;
        return Long.valueOf(String.valueOf(userId));
    }

    public boolean isExist(String thingsId) {
        List<String> envThingsIds = redisUtil.getListString(envThingsId);
        if (envThingsIds.size() == 0) {
            //查询数据库环卫things
            List<String> strings = toolCarDataMapper.selectEnvIsExist(Constants.envSId);
            if (strings.contains(thingsId)) {
                return true;
            }

            //插入redis
            redisUtil.lSet(envThingsId, strings);
        } else if (JSONObject.parseArray(JSON.toJSONString(envThingsIds.get(0)),
                String.class).contains(thingsId)) {
            return true;
        }
        return false;
    }

    private double getDistance(String thingsId) {
        double distance = 0d;
        String[] activeProfiles = env.getActiveProfiles();
        String activeProfile = activeProfiles[0];
        if (activeProfile.equals("prod")) {
            activeProfile = "DIS";
        } else if (activeProfile.equals("dev")) {
            activeProfile = "DEV";
        }
        Map<String, Object> map1 = toolCarDataMapper.selectTrid(activeProfile + thingsId);
        if (map1 != null) {
            Integer trid = Integer.valueOf(map1.get("trid").toString());
            Integer tid = Integer.valueOf(map1.get("tid").toString());
            Map<String, Object> pointList = AddressGEOUtil.pointList(trid, tid, getTime(0),
                    new Date().getTime(), 1, 1);
            Integer parseObject = JSON.parseObject(pointList.get("errcode").toString(), Integer.class);
            if (parseObject == 10000) {
                Map parseObject1 = JSON.parseObject(pointList.get("data").toString(), Map.class);
                List<Map<String, Object>> parseObject2 = JSON.parseObject(parseObject1.get("tracks").toString(), List.class);
                distance = Double.parseDouble(parseObject2.get(0).get("distance") + "") / 1000;
            }
        }
        return distance;
    }

    /**
     * 插入每天工作的设备
     *
     * @param reqMap
     * @param thingsId
     */
    private void insertOnlineEveryDay(Map<String, Object> reqMap, String thingsId) {

        if (!reqMap.containsKey(Constants.THINGS_RotateSpeed)) {

            reqMap.put(Constants.THINGS_RotateSpeed, "0");
        }

        if (!reqMap.containsKey(Constants.THINGS_EngineTotalHours)) {

            reqMap.put(Constants.THINGS_EngineTotalHours, "0");
        }

        if (!reqMap.containsKey(Constants.THINGS_Ignition)) {

            reqMap.put(Constants.THINGS_Ignition, "0");
        }

        // 转速、发动机总工时、点火电压有一个有值，就认为是工作了
        if (Orgin.getIntValue(reqMap, Constants.THINGS_RotateSpeed) > 0 ||
                Orgin.getIntValue(reqMap, Constants.THINGS_EngineTotalHours) > 0 ||
                Orgin.getIntValue(reqMap, Constants.THINGS_Ignition) > 10) {

            if (toolCarDataMapper.selectOnlineEveryDay(thingsId) == null) {

                toolCarDataMapper.insertOnlineEveryDay(thingsId);
            }
        }
    }

    /**
     * 故障预警 16
     * 获取报警信息之后，根据thingID获取该车主信息，进行推送
     * @param reqMap
     * @param thingsId
     */
    private void faultWarning(Map<String, Object> reqMap, String thingsId) {
        if (reqMap.get("faultList") != null) {
            List<Map<String, Object>> mapList = (List<Map<String, Object>>) reqMap.get("faultList");
            mapList.forEach(x -> {
                String fmiDescription = Orgin.getString(x, "spnDescription_fmiDescription");
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);

                // 某设备当天只推送一次该类型的消息  每天不限制推送次数，进行次数累加
                //List<Map<String, Object>> currentDayPushedList = toolCarDataMapper.selectPushFive(thingsId, 16);
                // if (currentDayPushedList.size() == 0) {     每天不限制推送次数，进行次数累加
                List<Map<String, Object>> userList =
                        carDataAbnormalTask.getUserList(thingsList, 7);
                String user_id = userList.get(0).get("o_id").toString();
                //查询推送的次数
                int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 16);
                // 限制推送次数 如果当天超过50条不再推送
                if(count <= 5) {
                    userList.forEach(item -> {
                        // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                        List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(Orgin.getString(item, "things_id"));
                        Map<String, Object> message = ownerCars.get(0);
                        item.put("brand", message.get("brand"));
                        item.put("car_type", message.get("car_type"));
                        item.put("model", message.get("model"));
                        item.put("things_id", message.get("things_id"));
                        item.put("contacts", message.get("contacts"));
                        item.put("phone", message.get("phone"));
                        item.put("car_no", message.get("car_no"));
                        item.put("longitude", reqMap.get("GAODElongitude"));
                        item.put("latitude", reqMap.get("GAODElatitude"));
                        item.put("user_id", message.get("o_id"));
                        item.put("fault_desc", message.get("fault_desc"));
                        try {
                            carDataAbnormalTask.jPushFmiDescription(item, Orgin.getString(item, "o_id"), fmiDescription, count + 1);
                            carDataAbnormalTask.jPushFmiDescription(item, Orgin.getString(item, "d_id"), fmiDescription, count + 1);
                        }catch (Exception e){
                            e.printStackTrace();
                            logger.error(e.getMessage());
                        }
                        // 如果area为空，根据经纬度解析出区域编码
                        if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                            reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                        }
                        //获取客服列表
                        List<Map<String, Object>> kfList = null;
                        reqMap.put("s_id", item.get("s_id"));
                        if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                            kfList = appDao.findUserByRAreaCode(reqMap);
                            if (null == kfList || kfList.size() == 0) {
                                kfList = appDao.findUserByRid(reqMap);
                            }
                        } else {
                            kfList = appDao.findUserByRid(reqMap);
                        }

                        // 循环推送消息给符合条件的客服
                        if (kfList.size() > 0) {
                            for (Map<String, Object> kfMap : kfList) {
                                try{
                                carDataAbnormalTask.jPushFmiDescription(item, kfMap.get("id").toString(), fmiDescription, count + 1);
                                } catch (Exception e){
                                    e.printStackTrace();
                                    logger.error(e.getMessage());
                                }
                            }
                        }

                        /*reqMap.put("s_id", item.get("s_id").toString()); // r_id为 7(管理员)的用户列表
                        List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                        guanliyuanList.forEach(guanliyuanItem -> {
                            String guanliyuanUserId = guanliyuanItem.get("id");
                            carDataAbnormalTask.jPushFmiDescription(item, guanliyuanUserId, fmiDescription, count + 1);
                        });*/
                    });
                }
                //}
            });
        }
    }



    //燃油液位预警 15 推送给司机、车主
    private void fuelGaugeWarning(Map<String, Object> reqMap, String thingsId) {
        if(reqMap.get("FuelGauge") != null) {
            int fuelGauge = Orgin.getIntValue(reqMap, "FuelGauge");
            Map paraMap = new HashMap<>();
            paraMap.put("thingsId", thingsId);
            //根据传过来得剩余油量计算剩余工作时长：由于传的是百分比油量，又没有具体得一个油箱容积暂时注销
/*      Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);// this would default to now
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
        String endDay = sdf.format(date);
        calendar.add(Calendar.DATE, -30);
        String startDay = sdf.format(calendar.getTime());
        paraMap.put("startDay", startDay);
        paraMap.put("endDay", endDay);
        String fuelConsumptionOfDayAvg = tSSsVehicleModelDao.getFuelConsumptionAvg(paraMap);*/
            if (15 <= fuelGauge && fuelGauge < 20) {
                Integer count = toolCarDataMapper.selectIsPush(thingsId, 20);
                if (count == 0) {
                    paraMap.put("type", 20);
                    toolCarDataMapper.insertOilLowByType(paraMap);
                    List<String> thingsList = new ArrayList<>();
                    thingsList.add(thingsId);
                    List<Map<String, Object>> userList =
                            carDataAbnormalTask.getUserList(thingsList, 6);
                    userList.forEach(item -> {
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "o_id"), fuelGauge);
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "d_id"), fuelGauge);

                    /*// 如果area为空，根据经纬度解析出区域编码
                    if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                        reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                    }
                    //获取客服列表
                    List<Map<String, Object>> kfList = null;
                    reqMap.put("s_id", item.get("s_id"));
                    if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                        kfList = appDao.findUserByRAreaCode(reqMap);
                        if (null == kfList || kfList.size() == 0) {
                            kfList = appDao.findUserByRid(reqMap);
                        }
                    } else {
                        kfList = appDao.findUserByRid(reqMap);
                    }

                    // 循环推送消息给符合条件的客服
                    if (kfList.size() > 0) {
                        for (Map<String, Object> kfMap : kfList) {
                            carDataAbnormalTask.jPushFuel(item, kfMap.get("id").toString(), fuelGauge);
                        }
                    }

                    reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                    List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                    guanliyuanList.forEach(guanliyuanItem -> {
                        String guanliyuanUserId = guanliyuanItem.get("id");
                        carDataAbnormalTask.jPushFuel(item, guanliyuanUserId, fuelGauge);
                    });*/
                    });
                }
            } else if (10 <= fuelGauge && fuelGauge < 15) {
                Integer count = toolCarDataMapper.selectIsPush(thingsId, 15);
                if (count == 0) {
                    paraMap.put("type", 15);
                    toolCarDataMapper.insertOilLowByType(paraMap);
                    List<String> thingsList = new ArrayList<>();
                    thingsList.add(thingsId);
                    List<Map<String, Object>> userList =
                            carDataAbnormalTask.getUserList(thingsList, 6);
                    userList.forEach(item -> {
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "o_id"), fuelGauge);
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "d_id"), fuelGauge);

                    /*// 如果area为空，根据经纬度解析出区域编码
                    if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                        reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                    }
                    //获取客服列表
                    List<Map<String, Object>> kfList = null;
                    reqMap.put("s_id", item.get("s_id"));
                    if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                        kfList = appDao.findUserByRAreaCode(reqMap);
                        if (null == kfList || kfList.size() == 0) {
                            kfList = appDao.findUserByRid(reqMap);
                        }
                    } else {
                        kfList = appDao.findUserByRid(reqMap);
                    }

                    // 循环推送消息给符合条件的客服
                    if (kfList.size() > 0) {
                        for (Map<String, Object> kfMap : kfList) {
                            carDataAbnormalTask.jPushFuel(item, kfMap.get("id").toString(), fuelGauge);
                        }
                    }

                    reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                    List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                    guanliyuanList.forEach(guanliyuanItem -> {
                        String guanliyuanUserId = guanliyuanItem.get("id");
                        carDataAbnormalTask.jPushFuel(item, guanliyuanUserId, fuelGauge);
                    });*/
                    });
                }

            } else if (5 <= fuelGauge && fuelGauge < 10) {
                Integer count = toolCarDataMapper.selectIsPush(thingsId, 10);
                if (count == 0) {
                    paraMap.put("type", 10);
                    toolCarDataMapper.insertOilLowByType(paraMap);
                    List<String> thingsList = new ArrayList<>();
                    thingsList.add(thingsId);
                    List<Map<String, Object>> userList =
                            carDataAbnormalTask.getUserList(thingsList, 6);
                    userList.forEach(item -> {
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "o_id"), fuelGauge);
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "d_id"), fuelGauge);

                   /* // 如果area为空，根据经纬度解析出区域编码
                    if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                        reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                    }
                    //获取客服列表
                    List<Map<String, Object>> kfList = null;
                    reqMap.put("s_id", item.get("s_id"));
                    if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                        kfList = appDao.findUserByRAreaCode(reqMap);
                        if (null == kfList || kfList.size() == 0) {
                            kfList = appDao.findUserByRid(reqMap);
                        }
                    } else {
                        kfList = appDao.findUserByRid(reqMap);
                    }

                    // 循环推送消息给符合条件的客服
                    if (kfList.size() > 0) {
                        for (Map<String, Object> kfMap : kfList) {
                            carDataAbnormalTask.jPushFuel(item, kfMap.get("id").toString(), fuelGauge);
                        }
                    }

                    reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                    List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                    guanliyuanList.forEach(guanliyuanItem -> {
                        String guanliyuanUserId = guanliyuanItem.get("id");
                        carDataAbnormalTask.jPushFuel(item, guanliyuanUserId, fuelGauge);
                    });*/
                    });
                }

            } else if (0 <= fuelGauge && fuelGauge < 5) {
                Integer count = toolCarDataMapper.selectIsPush(thingsId, 5);
                if (count == 0) {
                    paraMap.put("type", 5);
                    toolCarDataMapper.insertOilLowByType(paraMap);
                    List<String> thingsList = new ArrayList<>();
                    thingsList.add(thingsId);
                    List<Map<String, Object>> userList =
                            carDataAbnormalTask.getUserList(thingsList, 6);
                    userList.forEach(item -> {
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "o_id"), fuelGauge);
                        carDataAbnormalTask.jPushFuel(item, Orgin.getString(item, "d_id"), fuelGauge);

                    /*// 如果area为空，根据经纬度解析出区域编码
                    if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                        reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                    }
                    //获取客服列表
                    List<Map<String, Object>> kfList = null;
                    reqMap.put("s_id", item.get("s_id"));
                    if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                        kfList = appDao.findUserByRAreaCode(reqMap);
                        if (null == kfList || kfList.size() == 0) {
                            kfList = appDao.findUserByRid(reqMap);
                        }
                    } else {
                        kfList = appDao.findUserByRid(reqMap);
                    }

                    // 循环推送消息给符合条件的客服
                    if (kfList.size() > 0) {
                        for (Map<String, Object> kfMap : kfList) {
                            carDataAbnormalTask.jPushFuel(item, kfMap.get("id").toString(), fuelGauge);
                        }
                    }

                    reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                    List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                    guanliyuanList.forEach(guanliyuanItem -> {
                        String guanliyuanUserId = guanliyuanItem.get("id");
                        carDataAbnormalTask.jPushFuel(item, guanliyuanUserId, fuelGauge);
                    });*/
                    });
                }

            }
        }
    }
    // 高温预警 5,20分钟
    // 获取传来的thingID今日是不是第一次传来的，如果是就插入表中；如果不是，今日插入过数据，就进行推送，并判断是否推送超过10条，超过不推送
    public void waterTemperature1(Map<String, Object> reqMap, String thingsId) throws Exception {
        if(reqMap.get("WaterTemperature") != null) {
            int waterTemperature = Orgin.getIntValue(reqMap, "WaterTemperature");
            if (waterTemperature > 100) {
                Map<String, Object> map = toolCarDataMapper.selectWaterTemper(thingsId);
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                if (map == null) {
                    toolCarDataMapper.insertWaterTemper(thingsId);
                }else {
                    List<String> listByCreateTime = toolCarDataMapper.selectNowDayCountMessages(DateUtil.formatDate(new Date()), thingsId, 17);
                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                    //查询推送的次数
                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 17);
                    //限制当天推送次数 超过50条不再推送
                    if (count <= 5) {
                        if (!CollectionUtils.isEmpty(listByCreateTime)) {
                            String date = listByCreateTime.get(0);
                            //计算一下是否是否在两分钟之内
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            long min = DateUtil.dateDiff(date, sdf.format(new Date()), "yyyy-MM-dd HH:mm:ss");
                            if (min < 2) {
                                userList.forEach(item -> {
                                    if (Orgin.getString(item, "advice_name") != null) {
                                        try {
                                            carDataAbnormalTask.jPush(item, Orgin.getString(item, "o_id"), 1, 8, count + 1);
                                            //carDataAbnormalTask.jPush(item, Orgin.getString(item, "d_id"), 1, 8, count + 1);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            logger.error(e.getMessage());
                                        }
                                    } else {
                                        try {
                                            carDataAbnormalTask.jPush(item, Orgin.getString(item, "o_id"), 2, 8, count + 1);
                                            carDataAbnormalTask.jPush(item, Orgin.getString(item, "d_id"), 2, 8, count + 1);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            logger.error(e.getMessage());
                                        }
                                    }
                                    //插入推送
                                    messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 8);
                                    toolCarDataMapper.updateWaterCount(thingsId, Orgin.getIntValue(map, "water_count") + 1);
                                });
                            }
                        } else {
                            messageRecordDao.addMessageRecord(map);
                        }
                    }

                }

            }//水温是否>100
        }//判断if是否为空


    }


    // 高温预警 5,20分钟
    public void waterTemperature(Map<String, Object> reqMap, String thingsId) {
        //温度超过 100 度 为高温，一次为20秒
        if(reqMap.get("WaterTemperature") != null) {
            int waterTemperature = Orgin.getIntValue(reqMap, "WaterTemperature");
            if (waterTemperature > 100) {
                Map<String, Object> map = toolCarDataMapper.selectWaterTemper(thingsId);
                List<String> thingsList = new ArrayList<>();
                thingsList.add(thingsId);
                //查询5分钟今天是否推送
//            List<Map<String, Object>> mapFive =
//                    toolCarDataMapper.selectPushFive(thingsId, 17);
                //查询20分钟今天是否推送 (该条件持续高温预警被弃用)
//            List<Map<String, Object>> mapTwenty =
//                    toolCarDataMapper.selectPushFive(thingsId, 18);
                //出现一次推送一次，不再需要mapTwenty.size() == 0 为限制条件
                //if (mapTwenty.size() == 0) {
                if (map == null) {
                    toolCarDataMapper.insertWaterTemper(thingsId);
                } else if (Orgin.getIntValue(map, "water_count") % 15 == 0) {
                    //查询当天是否推送
                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 8);
                    String user_id = userList.get(0).get("o_id").toString();
                    //查询推送的次数
                    int count = toolCarDataMapper.selectPushCount(user_id, thingsId, 17);
                    //限制当天推送次数 超过50条不再推送
                    if (count <= 50) {
                        userList.forEach(item -> {
                            if (Orgin.getString(item, "advice_name") != null) {
                                carDataAbnormalTask.jPush(item, Orgin.getString(item, "o_id"), 1, 8, count + 1);
                                carDataAbnormalTask.jPush(item, Orgin.getString(item, "d_id"), 1, 8, count + 1);

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPush(item, kfMap.get("id").toString(), 1, 8, count + 1);
                                }
                            }

                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                            guanliyuanList.forEach(guanliyuanItem -> {
                                String guanliyuanUserId = guanliyuanItem.get("id");
                                carDataAbnormalTask.jPush(item, guanliyuanUserId, 1, 8, count + 1);
                            });*/
                            } else {
                                carDataAbnormalTask.jPush(item, Orgin.getString(item, "o_id"), 2, 8, count + 1);
                                carDataAbnormalTask.jPush(item, Orgin.getString(item, "d_id"), 2, 8, count + 1);

                            /*// 如果area为空，根据经纬度解析出区域编码
                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
                            }
                            //获取客服列表
                            List<Map<String, Object>> kfList = null;
                            reqMap.put("s_id", item.get("s_id"));
                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
                                kfList = appDao.findUserByRAreaCode(reqMap);
                                if (null == kfList || kfList.size() == 0) {
                                    kfList = appDao.findUserByRid(reqMap);
                                }
                            } else {
                                kfList = appDao.findUserByRid(reqMap);
                            }

                            // 循环推送消息给符合条件的客服
                            if (kfList.size() > 0) {
                                for (Map<String, Object> kfMap : kfList) {
                                    carDataAbnormalTask.jPush(item, kfMap.get("id").toString(), 2, 8, count + 1);
                                }
                            }

                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
                            guanliyuanList.forEach(guanliyuanItem -> {
                                String guanliyuanUserId = guanliyuanItem.get("id");
                                carDataAbnormalTask.jPush(item, guanliyuanUserId, 2, 8, count + 1);
                            });*/
                            }
                            //插入推送
                            messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 8);
                            toolCarDataMapper.updateWaterCount(thingsId, Orgin.getIntValue(map, "water_count") + 1);
                        });
                    }
                }
//                 else if (Orgin.getIntValue(map, "water_count") == 60 && mapTwenty.size() == 0) {//20分钟推送
//                    List<Map<String, Object>> userList = carDataAbnormalTask.getUserList(thingsList, 9);
//                    userList.forEach(item -> {
//                        if (Orgin.getString(item, "advice_name") != null) {
//                            carDataAbnormalTask.jPush(item, Orgin.getString(item, "o_id"), 1, 9);
//                            carDataAbnormalTask.jPush(item, Orgin.getString(item, "d_id"), 1, 9);
//
//                            // 如果area为空，根据经纬度解析出区域编码
//                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
//                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
//                            }
//                            //获取客服列表
//                            List<Map<String, Object>> kfList = null;
//                            reqMap.put("s_id", item.get("s_id"));
//                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
//                                kfList = appDao.findUserByRAreaCode(reqMap);
//                                if (null == kfList || kfList.size() == 0) {
//                                    kfList = appDao.findUserByRid(reqMap);
//                                }
//                            } else {
//                                kfList = appDao.findUserByRid(reqMap);
//                            }
//
//                            // 循环推送消息给符合条件的客服
//                            if (kfList.size() > 0) {
//                                for (Map<String, Object> kfMap : kfList) {
//                                    carDataAbnormalTask.jPush(item, kfMap.get("id").toString(), 1, 9);
//                                }
//                            }
//
//                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
//                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
//                            guanliyuanList.forEach(guanliyuanItem -> {
//                                String guanliyuanUserId = guanliyuanItem.get("id");
//                                carDataAbnormalTask.jPush(item, guanliyuanUserId, 1, 9);
//                            });
//                        } else {
//                            carDataAbnormalTask.jPush(item, Orgin.getString(item, "o_id"), 2, 9);
//                            carDataAbnormalTask.jPush(item, Orgin.getString(item, "d_id"), 2, 9);
//
//                            // 如果area为空，根据经纬度解析出区域编码
//                            if (reqMap.get("GAODElongitude") != null && reqMap.get("GAODElatitude") != null) {
//                                reqMap.put("area", appServiceImpl.regeoAdCode(reqMap.get("GAODElongitude").toString(), reqMap.get("GAODElatitude").toString()));
//                            }
//                            //获取客服列表
//                            List<Map<String, Object>> kfList = null;
//                            reqMap.put("s_id", item.get("s_id"));
//                            if (reqMap.containsKey("area") && !reqMap.get("area").toString().equals("")) {
//                                kfList = appDao.findUserByRAreaCode(reqMap);
//                                if (null == kfList || kfList.size() == 0) {
//                                    kfList = appDao.findUserByRid(reqMap);
//                                }
//                            } else {
//                                kfList = appDao.findUserByRid(reqMap);
//                            }
//
//                            // 循环推送消息给符合条件的客服
//                            if (kfList.size() > 0) {
//                                for (Map<String, Object> kfMap : kfList) {
//                                    carDataAbnormalTask.jPush(item, kfMap.get("id").toString(), 2, 9);
//                                }
//                            }
//
//                            reqMap.put("s_id", item.get("s_id").toString()); // r_id为7(管理员)的用户列表
//                            List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(reqMap);
//                            guanliyuanList.forEach(guanliyuanItem -> {
//                                String guanliyuanUserId = guanliyuanItem.get("id");
//                                carDataAbnormalTask.jPush(item, guanliyuanUserId, 2, 9);
//                            });
//                        }
//                        //插入推送
//                        messageRecordDao.addMessageRecordCount(Orgin.getString(item, "things_id"), 9);
//                        toolCarDataMapper.updateWaterCount(thingsId, 0);
//                    });
                else {
                    toolCarDataMapper.updateWaterCount(thingsId, Orgin.getIntValue(map, "water_count") + 1);
                }
            }
        }
    }


    private void pushKt(Map<String, Object> reqMap, String thingsId) {
        Map<String, Object> map2 = new HashMap<>();
        List<Map<String, Object>> objects = new ArrayList<>();
        String date = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now());
        if (reqMap.get("allFaultList") != null) {
            List<Map<String, Object>> mapList = (List<Map<String, Object>>) reqMap.get("allFaultList");
            mapList.forEach(faultMap -> {
                Map<String, Object> map = new HashMap<>();
                String spn = Orgin.getString(faultMap, "spn");
                map.put("fault_id", thingsId + "_" + spn + "_" + date);
                map.put("things_ids", thingsId);
                map.put("sample_time", Orgin.getString(faultMap, "sample_time"));
                map.put("spn", spn);
                map.put("spn_description", Orgin.getString(faultMap, "spn_description"));
                map.put("fmi", Orgin.getString(faultMap, "fmi"));
                map.put("fmi_description", Orgin.getString(faultMap, "fmi_description"));//1
                map.put("hi", Orgin.getString(faultMap, "hi"));//1
                map.put("fault_type", "1");
                map.put("alarm_type", "");//暂定不知道模拟量是否要传
                objects.add(map);
            });
        }
        int fuelGauge = Orgin.getIntValue(reqMap, "FuelGauge");
        //TODO 燃油液位低
        if (fuelGauge < 10 && fuelGauge > 0) {
            Map<String, Object> map = new HashMap<>();
            map.put("fault_id", thingsId + "_" + "1" + "_" + date);
            map.put("things_ids", thingsId);
            map.put("sample_time", Orgin.getString(reqMap, "sample_time"));
            map.put("spn", "");
            map.put("spn_description", "");
            map.put("fmi", "");
            map.put("fmi_description", "");//1
            map.put("hi", "");//1
            map.put("fault_type", "2");
            map.put("alarm_type", "1");
            objects.add(map);
        }
        //TODO 充电电压异常
//        if (){
//            Map<String, Object> map = new HashMap<>();
//            map.put("fault_id",thingsId+"_"+"spn"+"_"+date);
//            map.put("things_ids",thingsId);
//            map.put("sample_time",Orgin.getString(reqMap,"sample_time"));
//            map.put("fault_type","1");
//            map.put("alarm_type","2");
//            objects.add(map);
//        }
//        //TODO 机油压力
//        if (){
//            Map<String, Object> map = new HashMap<>();
//            map.put("fault_id",thingsId+"_"+"spn"+"_"+date);
//            map.put("things_ids",thingsId);
//            map.put("sample_time",Orgin.getString(reqMap,"sample_time"));
//            map.put("fault_type","1");
//            map.put("alarm_type","3");
//            objects.add(map);
//        }
//        //TODO 水温报警
//        if (){
//            Map<String, Object> map = new HashMap<>();
//            map.put("fault_id",thingsId+"_"+"spn"+"_"+date);
//            map.put("things_ids",thingsId);
//            map.put("sample_time",Orgin.getString(reqMap,"sample_time"));
//            map.put("fault_type","1");
//            map.put("alarm_type","4");
//            objects.add(map);
//        }
        map2.put("list", objects);
        if (objects.size() > 0) {
            //this.pushKtFault(map2);
        }
    }

    private void pushKtFault(Map<String, Object> map2) {
        Map tokenMap = relationService.getToken();
        String accessToken = Orgin.getString(tokenMap, "access_token");
        String tokenType = Orgin.getString(tokenMap, "token_type");
        HttpRequest sendData;
        String bodyText = "";
        Map bodyTe = null;
        //todo 推送完清除
        sendData =
                HttpRequest.post(postFC).bodyText(JSONObject.toJSONString(map2))
                        .contentType("application/json")
                        .charset("utf-8")
                        .header(Authorization, tokenType + " " + accessToken)
                        .host("internal.cel-cat.com.cn");
        bodyText = sendData.send().bodyText();
        bodyTe = JSON.parseObject(bodyText, Map.class);
    }

    private Long getTime(int time) {
        Date date = new Date();
        date.setDate(date.getDate());
        date.setHours(time);
        date.setMinutes(0);
        date.setSeconds(0);
        return date.getTime();
    }

    public void operateHeadMessage(Map<String, Object> reqMap)  {
        String thingsId = Orgin.getString(reqMap, "things_id");
        String sampleTime = Orgin.getString(reqMap, "sample_time");
        String hexStr = reqMap.get("head_message").toString().toUpperCase();
        hexStr = hexStr.toUpperCase();

        int flagIndexOf = 0;
        // 处理电机控制器报文1（主电机油门给定、电机信息）
        // 处理电机控制器报文2（泵电机油门给定、电机信息）
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F105) > -1 || hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E105) > -1) {
            // 整车控制器报文1（主电机状态、油门给定、制动深度给定等）
            // 整车控制器报文2（泵电机状态、油门给定、制动深度给定等）
            if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F105) > -1) {
                flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F105) + Constants.MOTORCONTROLLERMESSAGE_F105.length();
            } else if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E105) > -1) {
                flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E105) + Constants.MOTORCONTROLLERMESSAGE_E105.length();
            }

            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            // 已经按照 “电机状态、运行模式给定” 的二进制进行解析
            String djztStr = "";
            if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F105) > -1) {
                String djztBinStr =  toolCarDataService.hexString2binaryString(strArr[0]);  // 主电机状态、运行模式给定
                String[] djztStrArr =  ConverUtil.strToStrArr(djztBinStr);
                if(djztStrArr[1].equals("01")) {
                    djztStr += "运行;";
                } else if(djztStrArr[1].equals("10")) {
                    djztStr += "停止;";
                }
                if(djztStrArr[2].equals("00")) {
                    djztStr += "转速模式;";
                } else if(djztStrArr[2].equals("10")) {
                    djztStr += "转矩模式;";
                }
                if(djztStrArr[3].equals("01")) {
                    djztStr += "牵引;";
                } else if(djztStrArr[3].equals("10")) {
                    djztStr += "制动;";
                }
            } else if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E105) > -1) {
                String djztBinStr =  toolCarDataService.hexString2binaryString(strArr[0]);  // 泵电机状态、运行模式给定
                String[] djztStrArr =  ConverUtil.strToStrArr(djztBinStr);
                if(djztStrArr[1].equals("01")) {
                    djztStr += "运行;";
                } else if(djztStrArr[1].equals("10")) {
                    djztStr += "停止;";
                }
                if(djztStrArr[2].equals("00")) {
                    djztStr += "转速模式;";
                } else if(djztStrArr[2].equals("10")) {
                    djztStr += "转矩模式;";
                }
                if(djztStrArr[3].equals("01")) {
                    djztStr += "牵引;";
                }
            }

            String ymgdStr = strArr[4] + strArr[3]; // 油门给定的高字节 + 低字节
            int ymgdInter = Integer.parseInt(ymgdStr,16); // 油门给定的的值(10进制)

            String zdsdgdStr = strArr[6] + strArr[5]; // 制动深度的高字节 + 低字节
            int zdsdgdInter = Integer.parseInt(zdsdgdStr,16); // 制动深度的值(10进制)

            // 暂时没按照“电机转向给定”的二进制进行解析
            String djzxStr =  toolCarDataService.DecimalToBinary(Integer.parseInt(strArr[7])); // 电机转向给定

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F105) > -1) {
                paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', djzt='"+ (!djztStr.equals("") ? djztStr.substring(0, djztStr.length() - 1) : "") +"', ymgd="+ ymgdInter +", zdsdgd="+ zdsdgdInter +", djzx="+ djzxStr +"");
            } else if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E105) > -1) {
                paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', bdjzt='"+ (!djztStr.equals("") ? djztStr.substring(0, djztStr.length() - 1) :"") +"', ymgd="+ ymgdInter +", zdsdgd="+ zdsdgdInter +", djzx="+ djzxStr +"");
            }

            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F106) > -1) {
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F106) + Constants.MOTORCONTROLLERMESSAGE_F106.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            // 暂时没按照 “档位信息” 的二进制进行解析
            String dwxxStr =  toolCarDataService.DecimalToBinary(Integer.parseInt(strArr[0]));  // 档位信息

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', dwxx="+ dwxxStr +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F205) > -1) {
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F205) + Constants.MOTORCONTROLLERMESSAGE_F205.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            // 已经按照 “状态信息” 的二进制进行解析整车系统故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[1]);
            String[] zcxtgzStrArr = ConverUtil.strToStrArr8(binaryString);

            String zcxtgzStr = "";
            for (int i = 0; i < zcxtgzStrArr.length; i++) {
                if (zcxtgzStrArr[i].equals("1")) {
                    switch (i) {
                        case 1:
                            zcxtgzStr += "动力电池温度异常;";
                            break;
                        case 2 :
                            zcxtgzStr += "电机超速指示灯;";
                            break;
                        case 3 :
                            zcxtgzStr += "电机故障灯;";
                            break;
                        case 4 :
                            zcxtgzStr += "电机/电池过热故障;";
                            break;
                        case 5 :
                            zcxtgzStr += "动力蓄电池故障;";
                            break;
                        case 6 :
                            zcxtgzStr += "绝缘故障;";
                            break;
                        case 7 :
                            zcxtgzStr += "整车系统故障;";
                            break;
                    }
                }
            }

            String csztStr = strArr[4]; // 车速
            int csztInter = Integer.parseInt(csztStr,16); // 车速的值(10进制)

            String zdylStr = strArr[5]; // 制动压力
            int zdylInter = Integer.parseInt(zdylStr,16); // 制动压力的值(10进制)

            String bjqywStr = strArr[6]; // 变矩器油温
            int bjqywInter = Integer.parseInt(bjqywStr,16)-40; // 变矩器油温的值(10进制)

            if (bjqywInter < 0)
            {
                bjqywInter = 0;
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = zcxtgzStr;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', zcxtgz='"+ zcxtgzStr +"', cszt="+ csztInter +", zdyl="+ zdylInter +", bjqyw="+ bjqywInter +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF05) > -1) {
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF05) + Constants.MOTORCONTROLLERMESSAGE_FF05.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            // 暂时没按照 “报警信息” 的二进制进行解析
            String bjxxStr =  toolCarDataService.DecimalToBinary(Integer.parseInt(strArr[0]));  // 报警信息

            String djgzzsStr = strArr[1]; // 电机故障总数
            int djgzzsInter = Integer.parseInt(djgzzsStr,16); // 电机故障总数的值(10进制)

            String clztStr = strArr[2]; // 车辆状态
            int clztInter = Integer.parseInt(clztStr,16); // 车辆状态的值(10进制)

            String cdztStr =  toolCarDataService.DecimalToBinary(Integer.parseInt(strArr[3]));  // 充电状态
            String cldlStr =  toolCarDataService.DecimalToBinary(Integer.parseInt(strArr[4]));  // 车辆动力
            String qdzdlStr =  toolCarDataService.DecimalToBinary(Integer.parseInt(strArr[5]));  // 驱动力、制动力

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', bjxx="+ bjxxStr +", djgzzs="+ djgzzsInter +", clzt="+ clztInter +", cdzt="+ cdztStr +", cldl="+ cldlStr +", qdzdl="+ qdzdlStr +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F120) > -1 || hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E120) > -1) {
            if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F120) > -1) {
                flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F120) + Constants.MOTORCONTROLLERMESSAGE_F120.length();
            } else if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E120) > -1) {
                flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E120) + Constants.MOTORCONTROLLERMESSAGE_E120.length();
            }

            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            int mxdyInter = ((Integer.parseInt(strArr[1],16)) * 256 + (Integer.parseInt(strArr[0],16))); // 母线电压的值(10进制)(高字节+低字节)
            double dxjdlInter = ((Integer.parseInt(strArr[3],16)) * 256 + (Integer.parseInt(strArr[2],16))) * 0.5 - 1000; // 电机相电流的值(10进制)(高字节 + 低字节)
            int dxssscglInter = ((Integer.parseInt(strArr[7],16)) * 256 + (Integer.parseInt(strArr[6],16))) * 10; // 实时功率(电机实时输出功率)的值(10进制)(字节 + 高字节)

            if(dxjdlInter < 0)
            {
                dxjdlInter=0;
            }
            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', mxdy="+ mxdyInter +", dxjdl="+ dxjdlInter +", dxssscgl="+ dxssscglInter +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF19) > -1) {  // 总电压，总电流
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF19) + Constants.MOTORCONTROLLERMESSAGE_FF19.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            int int23 = ((Integer.parseInt(strArr[2],16)) * 256 + (Integer.parseInt(strArr[1],16)));
            // 总电流
            Double zdl = int23 * 0.5 - 500;
            // 总电压
            int zdy = (Integer.parseInt(strArr[4],16)) * 256 + (Integer.parseInt(strArr[3],16));

            // 剩余电量
            int soc = (Integer.parseInt(strArr[5], 16));

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', zdy="+ zdy +", zdl="+ zdl +", soc="+ soc +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F18D) > -1) { // 主电机温度，主控制器温度
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F18D) + Constants.MOTORCONTROLLERMESSAGE_F18D.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            // 主电机温度
            int djwd = ((Integer.parseInt(strArr[1],16)) - 40);
            // 主控制器温度
            int kzqwd = ((Integer.parseInt(strArr[2],16)) - 40);

            // 驱动电机故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[7] + strArr[6]);
            String[] zdjbjxxArr = ConverUtil.strToStrArr8(binaryString);
            String zdjbjxx = "";
            for (int i = 0; i < zdjbjxxArr.length; i++) {
                if(zdjbjxxArr[i].equals("1")) { // 1表示有故障
                    switch (i) {
                        case 0:
                            zdjbjxx += "致命故障;";
                            break;
                        case 1:
                            zdjbjxx += "堵转保护;";
                            break;
                        case 2:
                            zdjbjxx += "跛行状态;";
                            break;
                        case 3:
                            zdjbjxx += "VCU故障或无VCU;";
                            break;
                        case 4:
                            zdjbjxx += "超过最高限速;";
                            break;
                        case 5:
                            zdjbjxx += "超过峰值功率限制;";
                            break;
                        case 6:
                            zdjbjxx += "严重欠压;";
                            break;
                        case 7:
                            zdjbjxx += "短路保护;";
                            break;
                        case 8:
                            zdjbjxx += "控制器高温;";
                            break;
                        case 9:
                            zdjbjxx += "通讯故障;";
                            break;
                        case 10:
                            zdjbjxx += "过压报警;";
                            break;
                        case 11:
                            zdjbjxx += "机欠压报警;";
                            break;
                        case 12:
                            zdjbjxx += "电机过温;";
                            break;
                        case 13:
                            zdjbjxx += "控制器过温;";
                            break;
                        case 14:
                            zdjbjxx += "过流;";
                            break;
                        case 15:
                            zdjbjxx += "位置传感器故障;";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalZdjbjxx = zdjbjxx;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalZdjbjxx);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', djwd="+ djwd +", kzqwd="+ kzqwd +", zdjbjxx='"+ zdjbjxx +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E18D) > -1) { // 泵电机温度，泵控制器温度
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E18D) + Constants.MOTORCONTROLLERMESSAGE_E18D.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            // 泵电机温度
            int bdjwd = ((Integer.parseInt(strArr[1],16)) - 40);
            // 泵控制器温度
            int bkzqwd = ((Integer.parseInt(strArr[2],16)) - 40);

            // 泵电机故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[7] + strArr[6]);
            String[] bdjbjxxStrArr = ConverUtil.strToStrArr8(binaryString);

            String bdjbjxx = "";
            for (int i = 0; i < bdjbjxxStrArr.length; i++) {
                if (bdjbjxxStrArr[i].equals("1")) {
                    switch (i) {
                        case 0 :
                            bdjbjxx += "致命故障;";
                            break;
                        case 1 :
                            bdjbjxx += "堵转保护;";
                            break;
                        case 2 :
                            bdjbjxx += "跛行状态;";
                            break;
                        case 3 :
                            bdjbjxx += "VCU故障或无VCU;";
                            break;
                        case 4 :
                            bdjbjxx += "超过最高限速;";
                            break;
                        case 5 :
                            bdjbjxx += "超过峰值功率限制;";
                            break;
                        case 6 :
                            bdjbjxx += "严重欠压;";
                            break;
                        case 7 :
                            bdjbjxx += "短路保护;";
                            break;
                        case 8 :
                            bdjbjxx += "控制器高温;";
                            break;
                        case 9 :
                            bdjbjxx += "通讯故障;";
                            break;
                        case 10 :
                            bdjbjxx += "过压报警;";
                            break;
                        case 11 :
                            bdjbjxx += "欠压报警;";
                            break;
                        case 12 :
                            bdjbjxx += "电机过温;";
                            break;
                        case 13 :
                            bdjbjxx += "控制器过温;";
                            break;
                        case 14 :
                            bdjbjxx += "过流;";
                            break;
                        case 15 :
                            bdjbjxx += "位置传感器故障;";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = bdjbjxx;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', bdjwd="+ bdjwd +", bkzqwd="+ bkzqwd +", bdjbjxx='"+ bdjbjxx +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F11F) > -1) { // 主电机输出转矩，电机转速，当前电机的实际运行状态
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F11F) + Constants.MOTORCONTROLLERMESSAGE_F11F.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            int int23 = ((Integer.parseInt(strArr[3],16)) * 256 + (Integer.parseInt(strArr[2],16)));
            // 主电机输出转矩
            Double djsczj = int23 * 0.5;

            // 主电机转速
            int djzs = (Integer.parseInt(strArr[5],16)) * 256 + (Integer.parseInt(strArr[4],16));

            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] djztStrArr = ConverUtil.strToStrArr(binaryString);
            String djztStr = "";
            // 主电机的状态-运行，停止
            if (djztStrArr[0].equals("01")) {
                djztStr += "运行";
            } else if (djztStrArr[0].equals("10")) {
                djztStr += "停止";
            }
            // 主电机的状态-牵引，制动
            if (djztStrArr[1].equals("01")) {
                djztStr += "牵引";
            } else if (djztStrArr[1].equals("10")) {
                djztStr += "制动";
            }
            // 主电机的状态- N或P档-CCW方向-CW方向
            if (djztStrArr[2].equals("00") || djztStrArr[2].equals("11")) {
                djztStr += "N或P档";
            } else if (djztStrArr[2].equals("01")) {
                djztStr += "CCW方向";
            } else if (djztStrArr[2].equals("10")) {
                djztStr += "CW方向";
            }
            // 主电机的状态-转速模式，转矩模式
            if (djztStrArr[3].equals("00")) {
                djztStr += "转速模式";
            } else if (djztStrArr[3].equals("01")) {
                djztStr += "转矩模式";
            }

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', djsczj="+ djsczj +", djzs="+ djzs +", djzt='"+ djztStr +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E11F) > -1) { // 泵电机输出转矩，电机转速，当前电机的实际运行状态
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E11F) + Constants.MOTORCONTROLLERMESSAGE_E11F.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            int int23 = ((Integer.parseInt(strArr[3],16)) * 256 + (Integer.parseInt(strArr[2],16)));
            // 泵电机输出转矩
            Double bdjsczj = int23 * 0.5;
            // 泵电机转速
            int bdjzs = (Integer.parseInt(strArr[5],16)) * 256 + (Integer.parseInt(strArr[4],16));

            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] bdjztStrArr = ConverUtil.strToStrArr(binaryString);
            String bdjztStr = "";
            // 泵电机的状态-运行，停止
            if (bdjztStrArr[0].equals("01")) {
                bdjztStr += "运行";
            } else if (bdjztStrArr[0].equals("10")) {
                bdjztStr += "停止";
            }
            // 泵电机的状态-牵引，制动
            if (bdjztStrArr[1].equals("01")) {
                bdjztStr += "牵引";
            } else if (bdjztStrArr[1].equals("10")) {
                bdjztStr += "制动";
            }
            // 泵电机的状态- N或P档-CCW方向-CW方向
            if (bdjztStrArr[2].equals("00") || bdjztStrArr[2].equals("11")) {
                bdjztStr += "N或P档";
            } else if (bdjztStrArr[2].equals("01")) {
                bdjztStr += "CCW方向";
            } else if (bdjztStrArr[2].equals("10")) {
                bdjztStr += "CW方向";
            }
            // 泵电机的状态-转速模式，转矩模式
            if (bdjztStrArr[3].equals("00")) {
                bdjztStr += "转速模式";
            } else if (bdjztStrArr[3].equals("01")) {
                bdjztStr += "转矩模式";
            }

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', bdjsczj="+ bdjsczj +", bdjzs="+ bdjzs +", bdjzt='"+ bdjztStr +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_84D0) > -1) {  // BMS 发送电池包信息（电芯温度最值等）
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_84D0) + Constants.MOTORCONTROLLERMESSAGE_84D0.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr =  ConverUtil.strToStrArr(hexDataStr);

            // 电芯温度最大值
            int jxwdzdz = ((Integer.parseInt(strArr[0],16)) - 40);
            // 电芯温度最小值
            int jxwdzxz = ((Integer.parseInt(strArr[1],16)) - 40);
            // 电芯温度平均值
            int jxwdpjz = ((Integer.parseInt(strArr[2],16)) - 40);
            // 电芯温度最大值所在CSC编号
            int jxwzdz_csc_bh = ((Integer.parseInt(strArr[3],16)));
            // 电芯温度最大值所在CSC内温度探针编号
            int jxwzdz_csc_wdtzbh = ((Integer.parseInt(strArr[4],16)));
            // 电芯温度最小值所在CSC编号
            int jxwzxz_csc_bh = ((Integer.parseInt(strArr[5],16)));
            // 电芯温度最小值所在CSC内温度探针编号
            int jxwzxz_csc_wdtzbh = ((Integer.parseInt(strArr[6],16)));

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', jxwdzdz="+ jxwdzdz +", jxwdzxz="+ jxwdzxz +", jxwdpjz="+ jxwdpjz + ",jxwzdz_csc_bh="+ jxwzdz_csc_bh +", jxwzdz_csc_wdtzbh="+ jxwzdz_csc_wdtzbh + ",jxwzxz_csc_bh="+ jxwzxz_csc_bh +", jxwzxz_csc_wdtzbh="+ jxwzxz_csc_wdtzbh +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3201) > -1) { // DC-DC故障
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3201) + Constants.MOTORCONTROLLERMESSAGE_3201.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // DC-DC故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] dcdcgzStrArr = ConverUtil.strToStrArr8(binaryString);

            String dcdcgzStr = "";
            for (int i = 0; i < dcdcgzStrArr.length; i++) {
                if (dcdcgzStrArr[i].equals("1")) {
                    switch (i) {
                        case 2 :
                            dcdcgzStr += "DC-DC通讯超时;";
                            break;
                        case 3 :
                            dcdcgzStr += "DC-DC过热;";
                            break;
                        case 4 :
                            dcdcgzStr += "DC-DC过流;";
                            break;
                        case 5 :
                            dcdcgzStr += "DC-DC过载;";
                            break;
                        case 6 :
                            dcdcgzStr += "DC-DC输出过压;";
                            break;
                        case 7 :
                            dcdcgzStr += "DC-DC输入过压;";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = dcdcgzStr;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', dcdcgz='"+ dcdcgzStr +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3301) > -1) {     // 空压机状态
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3301) + Constants.MOTORCONTROLLERMESSAGE_3301.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 空压机温度
            int kyjwd = ((Integer.parseInt(strArr[3],16)));

            String kyjztStr = "";
            // 空压机状态
            if (strArr[5].equals("00")) {
                kyjztStr += "断开;";
            } else if (strArr[5].equals("01")) {
                kyjztStr += "工作;";
            } else if (strArr[5].equals("02")) {
                kyjztStr += "异常;";
            }

            // 空压机故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] kyjgzStrArr = ConverUtil.strToStrArr8(binaryString);
            String kyjgzStr = "";
            for (int i = 0; i < kyjgzStrArr.length; i++) {
                if (kyjgzStrArr[i].equals("1")) {
                    switch (i) {
                        case 2 :
                            kyjgzStr += "通讯超时;";
                            break;
                        case 3:
                            kyjgzStr += "过热;";
                            break;
                        case 4 :
                            kyjgzStr += "过流;";
                            break;
                        case 5 :
                            kyjgzStr += "过载;";
                            break;
                        case 6 :
                            kyjgzStr += "输入过压";
                            break;
                        case 7 :
                            kyjgzStr += "输入欠压;";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = kyjgzStr;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', kyjwd="+ kyjwd +", kyjzt="+  (!kyjztStr.equals("") ? kyjztStr.substring(0, kyjztStr.length() - 1) : "''") +", kyjgz='"+ kyjgzStr +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3401) > -1) { // 油泵状态
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3401) + Constants.MOTORCONTROLLERMESSAGE_3401.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 油泵温度
            int ybwd = ((Integer.parseInt(strArr[3],16)));

            String ybztStr = "";
            // 油泵状态
            if (strArr[5].equals("00")) {
                ybztStr += "断开;";
            } else if (strArr[5].equals("01")) {
                ybztStr += "工作;";
            } else if (strArr[5].equals("02")) {
                ybztStr += "异常;";
            }

            // 油泵故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] ybztStrArr = ConverUtil.strToStrArr8(binaryString);
            String ybgzStr = "";
            for (int i = 0; i < ybztStrArr.length; i++) {
                if (ybztStrArr[i] == "1") {
                    switch (i) {
                        case 2 :
                            ybgzStr += "通讯超时;";
                            break;
                        case 3 :
                            ybgzStr += "油泵过热;";
                            break;
                        case 4 :
                            ybgzStr += "油泵过流;";
                            break;
                        case 5 :
                            ybgzStr += "油泵过载";
                            break;
                        case 6:
                            ybgzStr += "油泵输入过压";
                            break;
                        case 7 :
                            ybgzStr += "油泵输入欠压";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = ybgzStr;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', ybwd="+ ybwd +", ybzt='"+  (!ybztStr.equals("") ? ybztStr.substring(0, ybztStr.length() - 1) : "") +"', ybgz='"+ (!ybgzStr.equals("") ? ybgzStr.substring(0, ybgzStr.length() - 1) : "") +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF20) > -1) {     // 充电情况
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF20) + Constants.MOTORCONTROLLERMESSAGE_FF20.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 已充电量 kwh
            int bccdgcycddl = ((Integer.parseInt(strArr[1]+strArr[0],16)) / 10);

            // 已充时间 min
            int bccdgcycdsj = ((Integer.parseInt(strArr[3]+strArr[2],16)) * 10) / 60;

            // 预计剩余充电时间 min
            int yjsycdsj = ((Integer.parseInt(strArr[5]+strArr[4],16)) * 10) / 60;

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', bccdgcycddl="+ bccdgcycddl +", bccdgcycdsj="+ bccdgcycdsj +", yjsycdsj="+ yjsycdsj + "");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3201) > -1) { // DC-DC故障
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3201) + Constants.MOTORCONTROLLERMESSAGE_3201.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // DC-DC故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] dcdcgzStrArr = ConverUtil.strToStrArr8(binaryString);

            String dcdcgzStr = "";
            for (int i = 0; i < dcdcgzStrArr.length; i++) {
                if (dcdcgzStrArr[i].equals("1")) {
                    switch (i) {
                        case 2 :
                            dcdcgzStr += "DC-DC通讯超时;";
                            break;
                        case 3 :
                            dcdcgzStr += "DC-DC过热;";
                            break;
                        case 4 :
                            dcdcgzStr += "DC-DC过流;";
                            break;
                        case 5 :
                            dcdcgzStr += "DC-DC过载;";
                            break;
                        case 6 :
                            dcdcgzStr += "DC-DC输出过压;";
                            break;
                        case 7 :
                            dcdcgzStr += "DC-DC输入过压;";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = dcdcgzStr;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', dcdcgz='"+ dcdcgzStr +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3301) > -1) {     // 空压机状态
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3301) + Constants.MOTORCONTROLLERMESSAGE_3301.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 空压机温度
            int kyjwd = ((Integer.parseInt(strArr[3],16)));

            String kyjztStr = "";
            // 空压机状态
            if (strArr[5].equals("00")) {
                kyjztStr += "断开;";
            } else if (strArr[5].equals("01")) {
                kyjztStr += "工作;";
            } else if (strArr[5].equals("02")) {
                kyjztStr += "异常;";
            }

            // 空压机故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] kyjgzStrArr = ConverUtil.strToStrArr8(binaryString);
            String kyjgzStr = "";
            for (int i = 0; i < kyjgzStrArr.length; i++) {
                if (kyjgzStrArr[i].equals("1")) {
                    switch (i) {
                        case 2 :
                            kyjgzStr += "通讯超时;";
                            break;
                        case 3:
                            kyjgzStr += "过热;";
                            break;
                        case 4 :
                            kyjgzStr += "过流;";
                            break;
                        case 5 :
                            kyjgzStr += "过载;";
                            break;
                        case 6 :
                            kyjgzStr += "输入过压";
                            break;
                        case 7 :
                            kyjgzStr += "输入欠压;";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = kyjgzStr;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', kyjwd="+ kyjwd +", kyjzt="+  (!kyjztStr.equals("") ? kyjztStr.substring(0, kyjztStr.length() - 1) : "''") +", kyjgz='"+ kyjgzStr +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3401) > -1) { // 油泵状态
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_3401) + Constants.MOTORCONTROLLERMESSAGE_3401.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 油泵温度
            int ybwd = ((Integer.parseInt(strArr[3],16)));

            String ybztStr = "";
            // 油泵状态
            if (strArr[5].equals("00")) {
                ybztStr += "断开;";
            } else if (strArr[5].equals("01")) {
                ybztStr += "工作;";
            } else if (strArr[5].equals("02")) {
                ybztStr += "异常;";
            }

            // 油泵故障
            String binaryString = toolCarDataService.hexString2binaryString(strArr[6]);
            String[] ybztStrArr = ConverUtil.strToStrArr8(binaryString);
            String ybgzStr = "";
            for (int i = 0; i < ybztStrArr.length; i++) {
                if (ybztStrArr[i] == "1") {
                    switch (i) {
                        case 2 :
                            ybgzStr += "通讯超时;";
                            break;
                        case 3 :
                            ybgzStr += "油泵过热;";
                            break;
                        case 4 :
                            ybgzStr += "油泵过流;";
                            break;
                        case 5 :
                            ybgzStr += "油泵过载";
                            break;
                        case 6:
                            ybgzStr += "油泵输入过压";
                            break;
                        case 7 :
                            ybgzStr += "油泵输入欠压";
                            break;
                    }
                }
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员
            String finalgzStr = ybgzStr;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', ybwd="+ ybwd +", ybzt='"+  (!ybztStr.equals("") ? ybztStr.substring(0, ybztStr.length() - 1) : "") +"', ybgz='"+ (!ybgzStr.equals("") ? ybgzStr.substring(0, ybgzStr.length() - 1) : "") +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF20) > -1) {     // 充电情况
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF20) + Constants.MOTORCONTROLLERMESSAGE_FF20.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 已充电量 kwh
            int bccdgcycddl = ((Integer.parseInt(strArr[1]+strArr[0],16)) / 10);

            // 已充时间 min
            int bccdgcycdsj = ((Integer.parseInt(strArr[3]+strArr[2],16)) * 10) / 60;

            // 预计剩余充电时间 min
            int yjsycdsj = ((Integer.parseInt(strArr[5]+strArr[4],16)) * 10) / 60;

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', bccdgcycddl="+ bccdgcycddl +", bccdgcycdsj="+ bccdgcycdsj +", yjsycdsj="+ yjsycdsj + "");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E5D0) > -1) {     // 电池信息
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E5D0) + Constants.MOTORCONTROLLERMESSAGE_E5D0.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 电池额定容量  Ah
            int dcedrl = (Integer.parseInt(strArr[1] + strArr[0],16));
            // 电池额定电压  V
            int dceddy = (Integer.parseInt(strArr[3] + strArr[2],16)) / 10;
            // 电池额定总量  kWh
            int dcedzl = (Integer.parseInt(strArr[5] + strArr[4],16)) / 10;

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', dcedrl="+ dcedrl +", dceddy="+ dceddy +", dcedzl="+ dcedzl + "");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F1D0) > -1) { // 电池包充放电量信息
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_F1D0) + Constants.MOTORCONTROLLERMESSAGE_F1D0.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 累计充电电量  kWh
            int ljcddl = (Integer.parseInt(strArr[2]+strArr[1]+strArr[0],16)) / 10;
            // 累计放电电量  kWh
            int ljfddl = (Integer.parseInt(strArr[5]+strArr[4]+strArr[3],16)) / 10;

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', ljcddl="+ ljcddl +", ljfddl="+ ljfddl +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF21) > -1) {   // 电池管理系统
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF21) + Constants.MOTORCONTROLLERMESSAGE_FF21.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 充电降功率运行
            String jgl = "";
            if (strArr[0].equals("00"))
            {
                jgl = "正常";
            } else if (strArr[0].equals("01"))
            {
                jgl = "降功率处理";
            }

            // 接触器状态
            String jcq = "";
            if (strArr[1].equals("00"))
            {
                jcq = "断开";
            } else if (strArr[1].equals("01"))
            {
                jcq = "吸合";
            }

            // 充电报警1
            String binaryString = toolCarDataService.hexString2binaryString(strArr[2]);

            String[] strArr1 = ConverUtil.strToStrArr8(binaryString);

            String faultText = "";
            for (int i = 0; i < strArr1.length; i++)
            {
                if (strArr1[i] == "1")
                {
                    switch (i) {

                        case 0:
                            faultText += "单体欠压2级;";
                            break;
                        case 1:
                            faultText += "单体欠压1级;";
                            break;
                        case 2:
                            faultText += "单体过压3级;";
                            break;
                        case 3:
                            faultText += "单体过压2级;";
                            break;
                        case 4:
                            faultText += "单体过压1级;";
                            break;
                        case 5:
                            faultText += "绝缘过低3级;";
                            break;
                        case 6:
                            faultText += "绝缘过低2级;";
                            break;
                        case 7:
                            faultText += "绝缘过低1级;";
                            break;
                    }
                }
            }

            // 充电报警2
            String binaryString1 = toolCarDataService.hexString2binaryString(strArr[3]);

            String[] strArr2 = ConverUtil.strToStrArr8(binaryString1);

            String faultText1 = "";
            for (int i = 0; i < strArr2.length; i++)
            {
                if (strArr2[i] == "1")
                {
                    switch (i){
                        case 0:
                            faultText1 += "通讯故障;";
                            break;
                        case 1:
                            faultText1 += "电池温度过低3级;";
                            break;
                        case 2:
                            faultText1 += "电池温度过低2级;";
                            break;
                        case 3:
                            faultText1 += "电池温度过低1级;";
                            break;
                        case 4:
                            faultText1 += "电池温度过高3级;";
                            break;
                        case 5:
                            faultText1 += "电池温度过高2级;";
                            break;
                        case 6:
                            faultText1 += "电池温度过高1级;";
                            break;
                        case 7:
                            faultText1 += "单体欠压3级;";
                            break;
                    }
                }
            }

            // 充电报警3
            String binaryString2 = toolCarDataService.hexString2binaryString(strArr[4]);

            String[] strArr3 = ConverUtil.strToStrArr8(binaryString2);

            String faultText2 = "";
            for (int i = 0; i < strArr3.length; i++)
            {
                if (strArr3[i] == "1")
                {
                    switch (i){
                        case 0:
                            faultText2 += "温差过大2级;";
                            break;
                        case 1:
                            faultText2 += "温差过大1级;";
                            break;
                        case 2:
                            faultText2 += "总压过低3级;";
                            break;
                        case 3:
                            faultText2 += "总压过低2级;";
                            break;
                        case 4:
                            faultText2 += "总压过低1级;";
                            break;
                        case 5:
                            faultText2 += "总压过高3级;";
                            break;
                        case 6:
                            faultText2 += "总压过高2级;";
                            break;
                        case 7:
                            faultText2 += "总压过高1级;";
                            break;
                    }
                }
            }

            // 充电报警4
            String binaryString3 = toolCarDataService.hexString2binaryString(strArr[5]);

            String[] strArr4 = ConverUtil.strToStrArr8(binaryString3);

            String faultText3 = "";
            for (int i = 0; i < strArr4.length; i++)
            {
                if (strArr4[i] == "1")
                {
                    switch (i){
                        case 0:
                            faultText3 += "充电过流1级;";
                            break;
                        case 1:
                            faultText3 += "放电过流1级;";
                            break;
                        case 2:
                            faultText3 += "放电过流2级;";
                            break;
                        case 3:
                            faultText3 += "放电过流1级;";
                            break;
                        case 4:
                            faultText3 += "压差过大3级;";
                            break;
                        case 5:
                            faultText3 += "压差过大2级;";
                            break;
                        case 6:
                            faultText3 += "压差过大1级;";
                            break;
                        case 7:
                            faultText3 += "温差过大3级;";
                            break;
                    }
                }
            }

            // 充电报警5
            String binaryString4 = toolCarDataService.hexString2binaryString(strArr[6]);

            String[] strArr5 = ConverUtil.strToStrArr8(binaryString4);

            String faultText4 = "";
            for (int i = 0; i < strArr5.length; i++)
            {
                if (strArr5[i] == "1")
                {
                    switch (i){
                        case 0:
                            faultText4 += "";
                            break;
                        case 1:
                            faultText4 += "充电过程致命故障;";
                            break;
                        case 2:
                            faultText4 += "放电过程致命故障;";
                            break;
                        case 3:
                            faultText4 += "SOC过低报警3级;";
                            break;
                        case 4:
                            faultText4 += "SOC过低报警2级;";
                            break;
                        case 5:
                            faultText4 += "SOC过低报警1级;";
                            break;
                        case 6:
                            faultText4 += "充电过流3级;";
                            break;
                        case 7:
                            faultText4 += "充电过流2级;";
                            break;
                    }
                }
            }

            String tempStr = strArr[7];
            String cdState = "";

            if (tempStr.equals("00"))
            {
                cdState = "充电枪未连接";

            }else if (tempStr.equals("01")){

                cdState = "充电中，快充";
            }
            else if (tempStr.equals("02")){

                cdState = "充电中，慢充";
            }
            else if (tempStr.equals("03")){

                cdState = "充电完成";
            }
            else if (tempStr.equals("04")){

                cdState = "充电故障";
            }

            String sid = toolCarDataMapper.selectSidByThingsId(thingsId);  // 根据ThingsID获取对应的sid
            List<Map<String, Object>> serverMapList = lockCarMapper.selectUserBySid(sid); // 根据sid获取对应的管理员

            String finalgzFaultTextStr = faultText;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzFaultTextStr);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            String finalgzFaultText1Str = faultText1;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzFaultText1Str);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            String finalgzFaultText2Str = faultText2;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzFaultText2Str);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            String finalgzFaultText3Str = faultText3;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzFaultText3Str);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            String finalgzFaultText4Str = faultText4;
            serverMapList.forEach(item -> {
                // 根据 things_id 获取该设备下的详细信息(things_id只有一个)
                List<Map<String, Object>> ownerCars = toolCarDataMapper.getOwnerCarByThingss(thingsId);
                Map<String, Object> message = ownerCars.get(0);
                item.put("brand", message.get("brand"));
                item.put("car_type", message.get("car_type"));
                item.put("model", message.get("model"));
                item.put("things_id", message.get("things_id"));
                item.put("contacts", message.get("contacts"));
                item.put("phone", message.get("phone"));
                item.put("car_no", message.get("car_no"));
                item.put("longitude", reqMap.get("GAODElongitude"));
                item.put("latitude", reqMap.get("GAODElatitude"));
                item.put("user_id", Orgin.getString(item, "id"));
                item.put("fault_desc",  finalgzFaultText4Str);

                //carDataAbnormalTask.jPushFaileDescription(item, Orgin.getString(item, "id"));
            });

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', bj1='"+ faultText +"', bj2='"+ faultText1 +"', bj3='"+ faultText2 + "', bj4='"+ faultText3 + "' , bj5='"+ faultText4 + "' , jglyx='"+ jgl +"' , jcqzt='"+ jcq +"', cdzt='"+ cdState +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_C2D0) > -1) {    // 电池各温度信息
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_C2D0) + Constants.MOTORCONTROLLERMESSAGE_C2D0.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            int zxh = Integer.parseInt(strArr[0],16);       // 帧序号
            int csc_bh = Integer.parseInt(strArr[1],16);    // CSC 编号
            int n = zxh  +  (zxh - 1) * 5;                       // 编号(帧 + (帧 - 1) * 5)

            String b2v_temp_n = "第" + n + "个探针温度：" + (Integer.parseInt(strArr[2],16) - 50) + "°C；";
            String b2v_temp_n1 = "第" + (n + 1) + "个探针温度：" + (Integer.parseInt(strArr[3],16) - 50) + "°C；";
            String b2v_temp_n2 = "第" + (n + 2) + "个探针温度：" + (Integer.parseInt(strArr[4],16) - 50) + "°C；";
            String b2v_temp_n3 = "第" + (n + 3) + "个探针温度：" + (Integer.parseInt(strArr[5],16) - 50) + "°C；";
            String b2v_temp_n4 = "第" + (n + 4) + "个探针温度：" + (Integer.parseInt(strArr[6],16) - 50) + "°C；";
            String b2v_temp_n5 = "第" + (n + 5) + "个探针温度：" + (Integer.parseInt(strArr[7],16) - 50) + "°C；";

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("zxh", zxh);
            paraMap.put("updateFieldStr", "csc_bh="+ csc_bh +", csc_tz_wd_or_ucell_n='"+ b2v_temp_n +"', csc_tz_wd_or_ucell_n1='"+ b2v_temp_n1 +"', csc_tz_wd_or_ucell_n2='"+ b2v_temp_n2 +"', csc_tz_wd_or_ucell_n3='"+ b2v_temp_n3 +"', csc_tz_wd_or_ucell_n4='"+ b2v_temp_n4 +"', csc_tz_wd_or_ucell_n5='"+ b2v_temp_n5 +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectricB2V(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectricB2V(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_C1D0) > -1) {    // 电池电芯电压
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_C1D0) + Constants.MOTORCONTROLLERMESSAGE_C1D0.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            int zxh = Integer.parseInt(strArr[0],16);       // 帧序号
            int csc_bh = Integer.parseInt(strArr[1],16);    // CSC 编号
            int n = zxh  +  (zxh - 1);                           // 编号(帧序号 + (帧序号 - 1))

            String b2v_ucell_n = "第" + n + "个电芯电压：" + new BigDecimal((Integer.parseInt(strArr[3] + strArr[2], 16))).divide(BigDecimal.valueOf(1000), 2, BigDecimal.ROUND_UP).doubleValue() + "V；";
            String b2v_ucell_n1 = "第" + (n + 1) + "个电芯电压：" + new BigDecimal((Integer.parseInt(strArr[5] + strArr[4], 16))).divide(BigDecimal.valueOf(1000), 2, BigDecimal.ROUND_UP).doubleValue()  + "V；";
            String b2v_ucell_n2 = "第" + (n + 2) + "个电芯电压：" + new BigDecimal((Integer.parseInt(strArr[7] + strArr[6], 16))).divide(BigDecimal.valueOf(1000), 2, BigDecimal.ROUND_UP).doubleValue()   + "V；";

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("zxh", zxh);
            paraMap.put("updateFieldStr", "csc_bh="+ csc_bh +", csc_tz_wd_or_ucell_n='"+ b2v_ucell_n +"', csc_tz_wd_or_ucell_n1='"+ b2v_ucell_n1 +"', csc_tz_wd_or_ucell_n2='"+ b2v_ucell_n2 +"'");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectricB2V(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectricB2V(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF24) > -1) {    // 电池管理系统报文七（铅蓄电池）
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_FF24) + Constants.MOTORCONTROLLERMESSAGE_FF24.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            // 蓄电池电压
            String xdcdy =  new BigDecimal((Integer.parseInt(strArr[1] + strArr[0], 16))).multiply(BigDecimal.valueOf(0.2)).doubleValue() + "";

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', xdcdy="+ xdcdy +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
        if(hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E6D0) > -1) {    // 电池信息 2(电池系统中 CSC 信息)
            flagIndexOf = hexStr.indexOf(Constants.MOTORCONTROLLERMESSAGE_E6D0) + Constants.MOTORCONTROLLERMESSAGE_E6D0.length();
            String hexDataStr = hexStr.substring(flagIndexOf, flagIndexOf + 16);
            String[] strArr = ConverUtil.strToStrArr(hexDataStr);

            int csc_zsm = ((Integer.parseInt(strArr[0],16)));                        // 电池系统中 CSC 总的数目（电池监控单 元）
            int pack_dx_zsm = ((Integer.parseInt(strArr[2] + strArr[1],16)));     // PACK 中单体电芯的总数目
            int pack_dx_tz_zsm = ((Integer.parseInt(strArr[4] + strArr[3],16)));  // PACK 中电芯温度点(探针)的总数目

            double dtpt_dy = new BigDecimal(((Integer.parseInt(strArr[5],16)))).multiply(BigDecimal.valueOf(0.1)).doubleValue();      // 单体平台电压(非实时变化的值）
            double dtpt_zd_dy = new BigDecimal(((Integer.parseInt(strArr[6],16)))).multiply(BigDecimal.valueOf(0.1)).doubleValue();;  // 单体可用最低电压(非实时变化的值）
            double dtpt_zg_dy = new BigDecimal(((Integer.parseInt(strArr[7],16)))).multiply(BigDecimal.valueOf(0.1)).doubleValue();;  // 单体可用最高电压(非实时变化的值）

            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("thinds_id", thingsId);
            paraMap.put("sample_time", ""+ sampleTime +"");
            paraMap.put("updateFieldStr", "sample_time='"+ sampleTime +"', csc_zsm="+ csc_zsm +", pack_dx_zsm="+ pack_dx_zsm +", pack_dx_tz_zsm="+ pack_dx_tz_zsm +", dtpt_dy="+ dtpt_dy +", dtpt_zd_dy="+ dtpt_zd_dy +", dtpt_zg_dy="+ dtpt_zg_dy +"");
            int result = toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            if(result == 1) { // 如果返回值为 1，表示执行 exist、insert 动作或 update 无影响的行数, 此时需要再次执行下面的sql；如果返回值为 2；则同时执行了 exist 和 update 动作，无需再次执行sql
                toolCarDataMapper.insertOrUpdatePCDataElectric(paraMap);
            }
        }
    }
}